-
linking source files
Hi guys!
I am writing a text adventure game, and it is all going really well at the moment.
I have written sevral source files for the game, and am using DevC++ in a project mode. when it comiples it, it says
COMPILE OK == LINK OK
this all sound possitive, but I am a bit weiry, that when I run the game, will it go the right file to read the code?
For exmaple, i have coded somthing like
(health<=0)
but will it go to the gameover file to read the code or just continue? I know all this sounds really silly as all I have to do is test it, but if I have probs, how can I fix them??
-
I'm not sure what to say accept no.. the game will start at int main(); whereever it is in your files. And you know .. it will do whatever you tell it to do in main.
-
Quote:
COMPILE OK == LINK OK
This probably means that your files are compiled and linked, and therfore an exe file is created.
When you execute the program, computer doesn't any longer use (or even need) the source files you've written. It just executes the commands that are stored in the exe file (which has been created from your source files by the compiler).
Code:
but will it go to the gameover file to read the code or just continue?
Well, if you've got something like:
gameover.cpp:
Code:
void GameOver()
{
//code...
}
main.cpp:
Code:
extern void GameOver();
int main()
{
//...
if(health<=0) GameOver();
//...
}
Surely, this is going to work. If you could post some code, it would be a lot easier to answer your question.
-
This is MAIN()
below is the main() function and basicly the main game it's self, this all compiles fine with on errors or link errors
Code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cctype> // files used
#include <windows.h>
#include <algorithm>
#include <conio.h>
using namespace std; // for cout and endl;
void intro();
void level1();
void plea();
void wizavillage();
void signpost();
void endingANDcredits();
extern void gameover();
/* Player Varibles*/
string pname; // player name
int health = 100; // player health;
int MAXhealth = 500; // player maximum health
int MINhealth = 1; // player minimum health
int gold = 0; // gold player has gathered
int Exp = 0; // experience gained
int spells = 0; // number of magic spells learned
string spellname; // string fof spell name
int level = 1; // player level
/* Enemy Varibles*/
string enemyname; // string for enemy name
int ehealth; // enemy health
int edamage; // enemy damage
int elevel; // enemy level;
bool edead; // booleen varible to decide is enemy defeated or active
bool ealive; // ""
/* Misc Vsribles*/
int size;
int x; // special varibles used in text scroll
char attack; // used in battle
char choice; // used in selection
char magic; // used in magic
int main(int argc, char *argv[])
{
SetConsoleTitle("W I Z A D O R A - BY PETER WATTS -"); // console Title
intro();
level1();
plea();
wizavillage();
signpost();
endingANDcredits();
if(health<=0) gameover();
return 0;
} // end main
void intro()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED| FOREGROUND_GREEN | FOREGROUND_INTENSITY );
cout << "\n\n";
cout <<"\t\t=============================================\n";
printf("\t\t# # # ##### #### #### #### #### ####\n"
"\t\t# # # # # # # # # # # # # #\n"
"\t\t# # # # # # # # # # #### # #\n"
"\t\t# # # # # #### # # # # # # ####\n"
"\t\t# # # # # # # # # # # # # # #\n"
"\t\t##### # ##### # # #### #### # # # #\n"
"\t\t=============================================\n"
"\t\t| | \n"
"\t\t| Press P to Play A New Game | \n"
"\t\t| | \n"
"\t\t| Press L to Load A Saved Game | \n"
"\t\t| | \n"
"\t\t| Press Q to Quit the Game | \n"
"\t\t--------------------------------------------- \n");
cout << "\n\n";
cout << "\tSelection >";
cin >> choice;
if (choice == 'l')
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_RED|FOREGROUND_INTENSITY );
system("cls");
printf("The load feature is not yet avalible...");
Sleep(2000);
system("cls");
intro();
}
else if (choice == 'q')
{
system("cls");
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_BLUE|FOREGROUND_INTENSITY );
printf("Goodbye then, please come back to save the kingdom soon...\n");
Sleep(3000);
exit(0);
}
else if (choice == 'p')
{
system("cls");
SetConsoleTextAttribute ( h, wOldColorAttrs);
cin.ignore();
level1();
}
else {
system("cls");
printf("You must enter one of the three commands!\n");
Sleep(2000);
system("cls");
intro();
}
} // end intro
void level1()
{
system("cls");
char senta[]="Hail adventurer!\nDo you seek glory, fame, fortune\nand even gold?\n"
"Then I welcome you to my land of magic and fantasy...\nI am Wizadora\n"
"and I need your help....\n";
size=strlen(senta);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",senta[x]);
}
Sleep(2000);
system("cls");
char sentb[]="But before you can start, I need to know your name.\nAs I cannot keep\n"
"calling you adventurer now can I?\n"
"\n\n"
"My name is: ";
size=strlen(sentb);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentb[x]);
}
getline ( cin, pname );
char sentc[]="\n\n"
"So, your name is ";
size=strlen(sentc);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentc[x]);
}
cout<<""<< pname <<""<<endl;
char sentd[]="Thats is a nice name!\nI hope we can get on well together...\n"
"Would you like to hear my story of why I have come to ask for your\n"
"aid ";
size=strlen(sentd);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentd[x]);
}
cout<<""<< pname <<"?"<<endl;
printf("\n\n"
"Press Y to hear her plea or N to continue anyway\n"
"\n\n");
cout << "Will you? ";
cin >> choice;
if (choice == 'n')
{
system("cls");
wizavillage();
}
else if (choice == 'y')
{
system("cls");
plea();
}
else {
printf("\n\n"
"You must enter yes or no...");
Sleep(2000);
level1(); // loop back to start of game to make sure question is aswered
}
} // end of level1
void plea()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_GREEN|FOREGROUND_INTENSITY );
system("cls");
char sentmp[]="The land of Wiza, which is basicly a land of child fantasy\n"
"has always been a peaceful land, where young trainee wizards\n"
"and witches roam, and practice their magic in the hope that\n"
"one day, they can use it to help bring peace to the world...\n"
"\n\n";
size=strlen(sentmp);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentmp[x]);
}
Sleep(2000);
system("cls");
char sentmpa[]="But one day, the evil witch DRUCILA cast an evil spell\n"
"on all the people who live in Wiza.\n"
"Her plan is to make all the people her slaves, so she can\n"
"have enough power to conquer the WHITE WILLOW, which is the\n"
"source of all our powers, and turn it evil...\n"
"\n\n";
size=strlen(sentmpa);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentmpa[x]);
}
Sleep(2000);
system("cls");
char sentmpb[]="But hope is not lost....\n"
"\n\n"
"I have been instructed by the WHITE WILLOW to challenge\n"
"DRUCIA and break her spell that she has over us.\n"
"I am all but an amatuer witch at the moment, that is why\n"
"I need your help to battle the monsters that DRUCILA has\n"
"crafted into Wiza...\n"
"I know if we work as a team, we can defeat DRUCILA and restore\n"
"peice to Wiza!\n"
"\n\n";
size=strlen(sentmpb);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentmpb[x]);
}
Sleep(2000);
system("cls");
SetConsoleTextAttribute ( h, wOldColorAttrs);
wizavillage();
} // end of plea
void wizavillage()
{
char sente[]="\tWIZA VILLAGE\n"
"\n\n"
"Welcome to my village.... Hmm, I guess it would be a good\n"
"Idea to stock up on magic or supplies before we venture into\n"
"The woods ahead, Ok then, were to first ";
size=strlen(sente);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sente[x]);
}
cout<<""<< pname <<"?"<<endl;
Sleep(2000);
system("cls");
signpost();
} // end function WizaVillage()
void signpost()
{
system("cls");
char sentf[]="Please Select a destination then hit ENTER\n"
"\n\n"
"Magic Shop == Press M\n"
"\n\n"
"Go to Wiza Woods == Press W\n"
"\n\n"
"Old Church == Press C\n"
"\n\n";
size=strlen(sentf);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",sentf[x]);
}
cout << "\tSelection: ";
cin >> choice;
}// end signpost
void endingANDcredits()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_GREEN|FOREGROUND_INTENSITY );
system("cls");
char senteog[]="Drucila Falls to the floor and trys to grab you\n"
"as you take a step back from her...\n"
"\n\n"
"The chapel begins to tumble to the floor, you manage to\n"
"escape through the large window on your left hand side.\n"
"\n\n"
"You run and run as the cathedral tumbles down behind you.\n"
"\n\n"
"The sun breaks through the clouds as they turn from dark\n"
"to white\n"
"In the faint rays of the sun, the monsters that littered the\n"
"ground turn back to the once happy people of Wiza...\n"
"\n\n"
"You then arrive back in the town square, and recive three\n"
"huge cheers as the entire town turns out to give their thanks!\n"
"\n\n"
"The WHITE WILLOW begins to glow and sprout with joy once more...\n"
"\n\n"
"You can see the light flowing from it's glistening bark...\n"
"\n\n"
"\n\n"
"With Drucila now defeated, and the land of Wiza finaly free, you can\n"
"now take a well earned break....\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"CONGATULATIONS!!!!!\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n";
size=strlen(senteog);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",senteog[x]);
}
Sleep(2000);
system("cls");
char senteogc[]="\tW I Z A D O R A\n"
"\t\n\n"
"\tProgramed by - Peter Watts\n"
"\t\n\n"
"\tWritten and Developed by - Peter Watts\n"
"\t\n\n"
"\tSound and Music - Steve THE MAN Childs\n"
"\t\n\n"
"\tSprite Design - Alan Pink\n"
"\t\n\n"
"\tText Color Program - Peter Watts\n"
"\t\n\n"
"\tMain dcpp Concept - Archwright Limited\n"
"\t\n\n"
"\tSpecial Thanks - Alan Pink\n"
"\t\n\n"
"\t Steve Childs\n"
"\t\n\n"
"\tLook out for the sequal soon!!!\n"
"\t\n\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"\t\tT H E E N D\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n"
"\n\n";
size=strlen(senteogc);
for(x=0;x<size;x++)
{
Sleep(40);
printf("%c",senteogc[x]);
}
Sleep(3000);
exit(0);
} // end of game
-
I've looked quickly through the code and I don't see anything wrong with it (at least at the first glance).
Though I haven't run it (working in linux only, and didn't want to install a windoze compiler... ;) ). You should test it of course, and then see if you get any strange behavior.
Looks like a nice game... Keep up the good work :D
-
wow... thats what im trying to be able to do! but im kind of far from being able to (i think...) but it looks nice... im with mathfan... i dont want to install windows compiler to try and play it
-
It looks good. If it compiles fine and links fine then it will create a .exe which will run anything in int main():
Code:
int main(int argc, char *argv[])
{
SetConsoleTitle("W I Z A D O R A - BY PETER WATTS -"); // console Title
intro();
level1();
plea();
wizavillage();
signpost();
endingANDcredits();
if(health<=0) gameover();
return 0;
} // end main
Code:
will it go to the gameover file to read the code or just continue?
If you didnt include gameover(); in int main() then it wouldnt have read the code. But since you did, it will.
I think the only thing is somehow you need to make that line "if(health<=0) gameover();" an infinite loop so it will be called exactly when it happens (if you die early in the game) and not at the end of all those functions being finished. This.. I'm not sure how to do. Something to do with seperate windows (using win32 API) I think.. maybe.