/*First of all, this is a simple Text based RPG which represents what can be done with just text. While I have no battle engine in this game (due to my limited time and the fact that most RPGs have VERY custom Battle Engines), it could easily be slipped into the game. The word "MYVARS" is a symbol for all the intergers that you can save. I use the word "MYVARS" to represent 'My variables" since you can put almost anything into that structure (including Chars, Char strings, etc.). This game is called "You Were Doomed From The Start"(C), and is copyrighted by Jeremy Carey Dressler, 2001. Feel free to edit the game, but please include my name in the credits as "Intial Game Engine Designer." Also another recommendation is that IF you create a battle engine, place all battle varibles into there own seperate file/structure. "Why?" you ask.... Simple... if you end up working on it for a long period of time, it sucks when you are constantly changing the save and are unable to reload a save. SOOO.. simply add a (hidden) function which JUST reloads your HP, MP, etc. I guess that is it... TTFN Noob P.S. If you have Questions: A. Visit my web site at- www.geocities.com/thelastjustcause/ B. E-mail me at- Noobsa44@aol.com*/ /* THE LEGAL STUFF..... No distribution of my program or any other data will be permitted. If this program causes any damage to you or your computer, I am not responsible. Basically, I'm not liable for the possible damage these files could do to you, your computer, your dog, or anyone or thing. Please do not seperate these files, if you are going to disregard my "No distribution" request. PLEASE NOTE that "No distribution" does not include creating your own game with this sample code, however, I still am not legally responsible for any problems this code causes you. TTFN Noob */ //Includes are simply little pieces of code that are included in the game to make //it work properly. Most of the time, includes come with the compiler and are FAIRLY //standard. Just to note, Pause and Pause1 are includes made by me and should be //included with this package. HOWEVER, just to be safe here they are (in comments): /* //This is the Pause.h code: #include "conio.h" void Pause() { printf("\nPress enter to continue..."); while(!kbhit()); if(getch()==NULL) getch(); } //This is the Pause1.h code: #include "conio.h" void Pause1() { //printf("\nPress enter please!"); while(!kbhit()); if(getch()==NULL) getch(); } */ //////////Beginning of real code!! NOW... #include "stdio.h"//needed for most primary functions, including printf(""); #include "random.h"//used for random #include "Pause.h"//my own pause function, it displays "please press any key!" #include "Pause1.h"//my own pause function, it doesn't display "please press any key!" #include "time.h"//sometimes need for random, if you have no random.h #include "dos.h"//needed for the delay function, not that if you have no delay function, simply remove delay from the game #include "string.h"//this is need to allow you to compare two words and see if they are the same #define SOURCEFILE "SAVE.dat"//This is required to save the game! //Note that you can have it specify a location (i.e.- C:\\MY_RPGs_NAME\\SAVES\\), but it isn't recommended //since if there is No Folder in that location, the save may or may not work properly //const are constants, for example, a constant would be the sun's light. //(while I know science says the sun will die out, have you ever seen that happen?) //Basically, it is a number that never changes const ML=63; //ML=Max Length const yes=1; //X=yes means X=1 const no=0; //X=no means X=0 char personsays[ML] = "";//The person asks for something, or inputs a word // it is placed here for string compare, ever piece of user input that requires //words will use this. While it could be placed in the structure, why would you wish to save //the last thing a person says? struct SAVEVARS//creating a structure will allows you to SAVE your settings..... {//it also gives the ints "global" rights, giving you the freedom to move the ints around //from one function to another! int color;//what color do you want? int Clock;//it was orgionally your "clock speed," but later became the text speed int room;//what room are you in? int Died;//have you died or not? int Key[10];//have you collected the keys? int room_eight_door_open;//is room eights door open? int last_action_not_move;//you should review to room after every "non-moving" action! int first_time_in_room_7;//was it your first time in room 7 int first_time_in_room_2;//is it the your first time in room 2? int game_completed;//have you just "beaten" the game? int key_fall_in_room_5;//Have you been in room 5? int opened_CD_saturn_in_room_3;//Did you open the Saturn in room 5? //Note that the [10] symbolizes the fact that key stands for 10 intergers (they call it an array) //it starts with the number "0", which will not be used and continues up to the number 9. //you have to pickup a key in each and every room to go to room 9, and then use the final key //char The_NAME[ML]; //the name of the character, if it is ever needed, at current //I don't feel it is need, however, once you name a character, you wish to save the //name, so it makes sense that is would be in the structure }; /////////////////////////////////////// //While it is said that globals are bad, they aren't bad if they are used in a //const form. That is, if you use a char globally, it is best that it doesn't change. //This is not true in a few cases, particularly if you have one char. that the user //"inputs" into for everything they do. In this case that is "Personsays", which is //declared somewhere above. //////////////////////WORDS USED///////////////////////// char use[ML] = "use"; ///this char. is to see if a person wants to "use" something char east[ML] = "e"; char north[ML] = "n";//another way of saying north,south,etc. char west[ML] = "w"; char south[ML] = "s"; /*char up[ML] = "up"; char down[ML] = "down"; char right[ML] = "right"; char left[ML] = "left"; *///maybe you'll add this to your word list char west2[ML] = "west";//for the n,s,e,w char east2[ML] = "east"; char north2[ML] = "north"; char south2[ML] = "south"; char help[ML] = "help"; /////This brings up a help screen //char map[ML] = "map"; /////Maybe you'll add a map! char pickup[ML] = "pickup"; ////Allows you to pick Items up //char debug[ML] = "debug"; //allows you to view the debug screen, good if needed! Not used in this version of the game! /*char onea[ML] = "one";//just another version of "1" char twoa[ML] = "two";//just another version of "2" char threea[ML] = "three";//just another version of "3" char foura[ML] = "four";//just another version of "4" char one[ML] = "1"; //used for a selection char two[ML] = "2"; //used for a selection char three[ML] = "3"; //used for a selection char four[ML] = "4"; //used for a selection */ //While those numbers are not needed, I would HIGHLY recommend that you NEVER //allow the user to be trust to ONLY input a number..... I would have it convert the //word to a number using NUMBER = atoi(Personsays); HOWEVER, I did not do this because //not all compilers have atoi(char);....... char key[ML] = "key";//use->key, maybe to get to room 9? char keys[ML] = "keys"; //char go[ML] = "go";//this will be another word for move.... char quit[ML] = "q";//just press "Q" to quit...... char quit1[ML] = "quit";/////this will also be used for quit char save[ML] = "save";//this will allow you to save the game..... char load[ML] = "load";//this is to load a game char yes1[ML] = "yes";//to say yes to a question char yes2[ML] = "y";//to say yes to a question ///////////////////////////////////////////////////////////////// //////////////////////////////////////////////////// /////////////////////////////////////////////////////// /*Just as a note, you always have to have a list of all functions you use in your program before you produce any of those functions, except for main which is require to run the program and is expected in the program. This display of functions is know as declerations if I'm not mistaken*/ void TCOLOR(struct SAVEVARS *MYVARS);//allows you to change the color in the game void ChangeColor(struct SAVEVARS *MYVARS);//changes the color EVERYTIME if color==0, else it reaffirms that the color is the same.. //since modern computers are fast enought to keep up with this "rechecking" it is best that it occurs after every letter. void DelayA(struct SAVEVARS *MYVARS);//Delay simply delays the print based upon your print selection void Sampleprintprogram(struct SAVEVARS *MYVARS);//just the example program to print something in color void Print(struct SAVEVARS *MYVARS, char *string);//this is the program you use to print stuff. void Clockspeed(struct SAVEVARS *MYVARS);//To find out your clock speed void Move_N(struct SAVEVARS *MYVARS);//moving north void Move_S(struct SAVEVARS *MYVARS);//moving south void Move_E(struct SAVEVARS *MYVARS);//moving east void Move_W(struct SAVEVARS *MYVARS);//moving west void Display_room(struct SAVEVARS *MYVARS);//it finds the new room, and displays the "room description" void Room1(struct SAVEVARS *MYVARS);//display room 1 void NowWhat(struct SAVEVARS *MYVARS);//What do you wish to do next? void Save_file(struct SAVEVARS *source,char *filename);//This allows you to save the file! void Load_file(struct SAVEVARS *dest,char *filename);//This allows you to load the file! void Pick_up(struct SAVEVARS *MYVARS);//Allows you to "pickup" a "key" void KEY(struct SAVEVARS *MYVARS);//this allows you to use the key, based on the room void Use(struct SAVEVARS *MYVARS);//allows you to use the keys void Game_finished(struct SAVEVARS *MYVARS);//You finished the game! void Title(struct SAVEVARS *MYVARS);//Have a title for the game! void Help(struct SAVEVARS *MYVARS);//This is to help the user! void Credits(struct SAVEVARS *MYVARS);//show the credits! ///////////////////////////////////////////// /////////////////////////////// ///////////////////////////////////////////// /////////////////////////////// ///////////////////////////////////////////// /////////////////////////////// ///////////////////////////////////////////// /////////////////////////////// ///////////////////////////////////////////// /////////////////////////////// ///////////////////////////////////////////// /////////////////////////////// /////////////////////////////////////////////Credits/////////////////////////////// void Credits(struct SAVEVARS *MYVARS) { Print(MYVARS,"Game made by, designed by, spell checked by and everything else...\n\r"); Print(MYVARS," Jeremy Carey-dressler (noob)!\n\r"); Print(MYVARS,"Special Thanks To: DoubleJ\n\r and.....\n\r Players like you!"); } /////////////////////////////////////////////Help!/////////////////////////////// void Help(struct SAVEVARS *MYVARS) { Print(MYVARS,"This game is quite simple, with very few words used...\n\r"); Print(MYVARS,"The word list consists of: \"save\", \"load\", \"use\",\"pickup\",\n\r"); Print(MYVARS,"\quit\",\"q\" (another form of quit),\"north\",\"south\",\"east\",\"west\"\n\r"); Print(MYVARS,"\"n\",\"s\",\"e\",\"w\",\"key\" and finally \"keys\".\n\rThat is the word list! Good luck and hope you enjoy! TTFN\n\n\rNoob\n\r"); } /////////////////////////////////////////////Title/////////////////////////////// void Title(struct SAVEVARS *MYVARS) { Print(MYVARS," You Were Doomed From The Start! V. 1.0\n\n\n\r"); //Yeah.... I know, a VERY cheese title! } /////////////////////////////////////////////Game_finished ////////////////////////////// void Game_finished(struct SAVEVARS *MYVARS) { Print(MYVARS,"\n\n\rI guess that is the end of you... However, you still\n\r"); Print(MYVARS,"beat the game, which means I should give you some kind of prize!\n\r"); Print(MYVARS,"hmmmm....... How about a game of \"PuckMan?\" Oh wait, that is\n\r"); Print(MYVARS,"slready on my other game.... grumble.... Well the least I can do\n\r"); Print(MYVARS,"is say \"Congrads!\" and here come the credits:\n\n\r"); } /////////////////////////////////////////////Use/////////////////////////////// void Use(struct SAVEVARS *MYVARS) { Print(MYVARS,"What would you like to use? "); scanf("%s",personsays); printf("\n"); if(!strcmp(personsays,key)||!strcmp(personsays,keys)) { if(MYVARS->room==8) { if(MYVARS->Key[1]==yes)//you must have all of the keys (except room 9)! if(MYVARS->Key[2]==yes) if(MYVARS->Key[3]==yes) if(MYVARS->Key[4]==yes) if(MYVARS->Key[5]==yes) if(MYVARS->Key[6]==yes) if(MYVARS->Key[7]==yes) if(MYVARS->Key[8]==yes) { Print(MYVARS,"You place all the keys into the 8 key-holes and a door to the south opens!!\n\r"); MYVARS->room_eight_door_open=yes; return; } else if(MYVARS->room_eight_door_open==no) { Print(MYVARS,"You don't have all the keys!!"); return; } else { if(MYVARS->room==8)//while this shouldn't be needed, I would like //to ensure that it knows I'm talking about room 8! { Print(MYVARS,"You already used all the keys!"); return; } } } if(MYVARS->room==9) { if(MYVARS->Key[9]==yes) { MYVARS->Died=yes; Print(MYVARS,"\n\rMy, My, you just fell into a Double J pit and it seems\n\rthese Double Js "); Print(MYVARS,"don't really like you...\n\r"); MYVARS->game_completed=yes; return; } else { Print(MYVARS,"\n\rYou already used all the keys to get into this room! Perhaps\n\rtheir "); Print(MYVARS,"is another key somewhere around here!\n\r"); } } } } /////////////////////////////////////////////Key/////////////////////////////// void KEY(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 1://each number in the "case _" symbolizes the current room number if(MYVARS->Key[1]==no)//if you don't have the key... { MYVARS->Key[1]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break;//this exits out of the "switch/case statement" case 2: if(MYVARS->Key[2]==no)//if you don't have the key... { MYVARS->Key[2]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 3: if(MYVARS->Key[3]==no)//if you don't have the key... { MYVARS->Key[3]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 4: if(MYVARS->Key[4]==no)//if you don't have the key... { MYVARS->Key[4]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 5: if(MYVARS->Key[5]==no)//if you don't have the key... { MYVARS->Key[5]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 6: if(MYVARS->Key[6]==no)//if you don't have the key... { MYVARS->Key[6]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 7: if(MYVARS->Key[7]==no)//if you don't have the key... { MYVARS->Key[7]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 8: if(MYVARS->Key[8]==no)//if you don't have the key... { MYVARS->Key[8]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; case 9: if(MYVARS->Key[9]==no)//if you don't have the key... { MYVARS->Key[9]=yes;//You now have it... Print(MYVARS,"You got the key from room "); printf("%d",MYVARS->room); Print(MYVARS,"!!"); } else { Print(MYVARS,"You already have the key!!"); } break; default: Print(MYVARS,"\n\rERROR! There is no room where you are!!!"); break; } } /////////////////////////////////////////////Pick_up/////////////////////////////// void Pick_up(struct SAVEVARS *MYVARS) { Print(MYVARS,"\n\rWhat would you like to pickup? "); if(MYVARS->Died==yes){return;}//before every scanf, you should have a "death check" scanf("%s",personsays); printf("\n"); if(!strcmp(personsays,key)) { KEY(MYVARS); return; } else { Print(MYVARS,"How do I pickup \""); printf("%s",personsays); Print(MYVARS,"?!?\""); return; } } /////////////////////////////////////////////Save_file/////////////////////////////// void Save_file(struct SAVEVARS *source,char *filename) { FILE *fp; if((fp = fopen(filename,"wb"))==NULL) { printf("\nERROR! Could not save (i.e. Open a file route) \"SAVE.dat\" file!!\n"); //Most likely because your using a directory //this is invalid OR your program is on a floppy disc/CD-R(W) //note that SOMETIMES this will not work on a floppy, othertimes it does. fclose(fp); return; } fwrite(source,sizeof(struct SAVEVARS),1,fp); fclose(fp); printf("\nFILE SAVED!\n"); } /////////////////////////////////////////////Load_file////////////////////////////// void Load_file(struct SAVEVARS *source,char *filename) { FILE *fp; srand( (unsigned)time( NULL ) );//randomize before you load the game... just a good place to insert //a "randomizer" if((fp = fopen(filename,"rb"))==NULL) { printf("\nERROR! Could not open TLJC.dat file!!\n"); //Most likly because your using a directory //this is invalid OR the program (or another program for that matter //has wrecked the file! fclose(fp); return; } if(!fp) { printf("THERE IS NO FILE!!!");//you can load a non-existant file return; } else { clrscr(); //printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); //for those who CAN'T use clrscr();, use these \n's... fread(source,sizeof(struct SAVEVARS),1,fp); fclose(fp); } srand( (unsigned)time( NULL ) ); //Randomizing the game after it has loaded so that the EXACT same thing doesn't //reoccur after everytime you load the game! (specifically in the battle department) } /////////////////////////////////////////////Room 9/////////////////////////////// void Room9(struct SAVEVARS *MYVARS) { if(MYVARS->Key[9]==no) //You don't have the key { Print(MYVARS,"\n\rYou enter this room with the hope that you can leave this\n\r"); Print(MYVARS,"place.... As fate would have it, you see a key hole... =/\n\r"); Print(MYVARS,"Then you see a key kindly placed on a velvet chair next to the key hole!"); } else { Print(MYVARS,"\n\rYou enter this room with the hope that you can leave this\n\r"); Print(MYVARS,"place.... As fate would have it, you see a key hole...!\n\r"); Print(MYVARS,"You also note the chair where the key was sitting.... However,\n\r"); Print(MYVARS,"that is unimportant compared to your desire to get out of this place...\n\r"); Print(MYVARS,"TO GO ANYWHERE BUT BE HERE.... Maybe using that key isn't such a bad idea!"); } } /////////////////////////////////////////////Room 8/////////////////////////////// void Room8(struct SAVEVARS *MYVARS) { if(MYVARS->room_eight_door_open==no) { Print(MYVARS,"You see 8 tiny little holes in the south wall, holes that keys could fit "); Print(MYVARS,"into!"); } else { Print(MYVARS,"The door to the south is open due to your use of the 8 keys!"); } if(MYVARS->Key[8]==no) //You don't have the key Print(MYVARS,"\n\rYou note a key sitting part-way-under the carpet in the middle of the room."); else Print(MYVARS,"\n\rYou note a shuffled up carpet in the middle of the room!"); Print(MYVARS,"\n\rThen you begin to examine the way in which you can exit. You see exits\n\rto the East"); if(MYVARS->room_eight_door_open==no) Print(MYVARS," and West."); else Print(MYVARS,", West and South!"); } /////////////////////////////////////////////Room 7/////////////////////////////// void Room7(struct SAVEVARS *MYVARS) { if(MYVARS->first_time_in_room_7==yes) { MYVARS->first_time_in_room_7=no; Print(MYVARS,"You enter a room full of lovely art... You see a piece of art that really\n\r"); Print(MYVARS,"looks interesting to you... It is a picture of a key, with the title \"The Key.\""); if(MYVARS->Key[7]==no) //You don't have the key Print(MYVARS,"As you dust off the name cover, a key falls to the floor...\n\r"); else Print(MYVARS,"You notice that the name cover doesn't have any dust on it anymore!\n\r"); Print(MYVARS,"You look about and note that there are rooms to the West and North of here."); } else { Print(MYVARS,"You enter a room full of lovely art... However, most of the art is poorly\n\rdone. Truely the only good piece is \"The Key.\""); if(MYVARS->Key[7]==no) //You don't have the key Print(MYVARS," Speaking of, there is a key\n\rsitting below the picture \"The Key.\""); else { Print(MYVARS," It seems funny that that\n\rpicture would have a key hidden on it..."); Print(MYVARS," You check all the rest of the\n\rpictures for keys, but have no luck."); } Print(MYVARS," You look about and note that there are\n\rrooms to the North and West of here."); } } /////////////////////////////////////////////Room 6/////////////////////////////// void Room6(struct SAVEVARS *MYVARS) { Print(MYVARS,"Oh, my, their is a lot of computer stuff in this room! You walk up\n\r"); Print(MYVARS,"to one of the computer desks and see hundreds of CD-Roms, a scanner,\n\r"); Print(MYVARS,"a fax, a printer, and of course a computer with monitor and keyboard.\n\r"); Print(MYVARS,"You turn on the monitor and computer, let it boot up, and start looking\n\r"); Print(MYVARS,"for any evidence of who was working here. You start a search, and put your\n\r"); Print(MYVARS,"fingers onto the keyboard and..."); if(MYVARS->Key[6]==no) //You don't have the key { Print(MYVARS," You note that just between \"esc\" and\n\rthe \"F1\" keys, is a key!"); Print(MYVARS," After completeing your search, you find nothing...\n\r"); } else { Print(MYVARS," Begin typing... After an hour of looking,\n\ryou find nothing, almost as"); Print(MYVARS," if the PC had JUST been shipped here and\n\rwas waiting for its owner! "); } Print(MYVARS,"Now you feel you're just about ready to leave...\n\rYou can go North or South."); } /////////////////////////////////////////////Room 5/////////////////////////////// void Room5(struct SAVEVARS *MYVARS) { Print(MYVARS,"You walk into this room expecting to see more of the same oddities\n\r"); Print(MYVARS,"that you have seen in some of the other rooms. To your suprise, this\n\r"); Print(MYVARS,"Room lacks a Double J statue or a computer or some other strange relic.\n\r"); Print(MYVARS,"This room is more like a hall, with torches on both sides to light the\n\r"); Print(MYVARS,"way. Then you pass by a clock which reads one minute past 12 o'clock.\n\r"); Print(MYVARS,"See that the clock doesn't work, you decide to fiddle with the clock's\n\r"); Print(MYVARS,"hands. "); if(MYVARS->key_fall_in_room_5==no) { Print(MYVARS,"Then you hear something strange.... It sounded like something\n\r"); Print(MYVARS,"dropped. "); MYVARS->key_fall_in_room_5=yes; } else { Print(MYVARS,"However, this time no more keys fall from the sky!\n\r"); } if(MYVARS->Key[5]==no) //You don't have the key Print(MYVARS,"You turn around and see a key which must have come from the sky!"); else Print(MYVARS,"Since no more keys have come from the clock, and you picked up\n\rthe one that did, there is nothing on the floor... except for the cold stone."); Print(MYVARS,"\n\rAfter this quick examination of the room, you look for the exits...\n\r"); Print(MYVARS,"You see that there are exits to the West and South."); } /////////////////////////////////////////////Room 4/////////////////////////////// void Room4(struct SAVEVARS *MYVARS) { Print(MYVARS,"You walk into this almost empty room, and then you notice how slippery the floor"); Print(MYVARS,"is. Then you see a statue... a statue of a quite ugly monster. The plaque on\n\r"); Print(MYVARS,"its base says \"Beware of the mighty Double J!\" You wonder where in the\n\r"); Print(MYVARS,"world would a \"Double J\" exist. For that matter what is a \"Double J?\"\n\r"); Print(MYVARS,"Then you start to examine this creatures round, stuby-legged body. His\n\r"); Print(MYVARS,"teeth are very interesting since they must be 10 inches long and as\n\rsharp as any knife you could imagine!!"); if(MYVARS->Key[4]==no) //You don't have the key Print(MYVARS," You then see a key stuck on one\n\rof the Double J's teeth!!"); Print(MYVARS," It seems as if you've out stayed your\n\rwelcome as you hear something rattling "); Print(MYVARS,"about behind the southern wall.\n\rMaybe you go out to the eastern or western "); Print(MYVARS,"rooms!"); } /////////////////////////////////////////////Room 3/////////////////////////////// void Room3(struct SAVEVARS *MYVARS) { Print(MYVARS,"You enter into a shrine like room with Saturns sitting EVERYWHERE.\n\r"); Print(MYVARS,"Then you see a TV with a video game system called the Saturn on top "); Print(MYVARS,"of the\n\rTV."); if(MYVARS->opened_CD_saturn_in_room_3==no) { Print(MYVARS," You see that there is an open button on this system.\n\rYou click the "); Print(MYVARS,"button to see that it"); } else Print(MYVARS," You see the opened system which"); if(MYVARS->Key[3]==no) //You don't have the key { if(MYVARS->opened_CD_saturn_in_room_3==no) Print(MYVARS," contains a key!\n\r"); else Print(MYVARS," still holds the key.\n\r"); } else Print(MYVARS," at one point in time contianed a key!\n\r"); Print(MYVARS,"You then notice that there are exits to the South and East."); MYVARS->opened_CD_saturn_in_room_3=yes; } /////////////////////////////////////////////Room 2/////////////////////////////// void Room2(struct SAVEVARS *MYVARS) { Print(MYVARS,"You enter into a BATHROOM!?! You don't understand why there are no\n\r"); Print(MYVARS,"doors, but perhaps there is a good reason.... Then you begin to look\n\r"); Print(MYVARS,"around to see all that you can see. You see quite a few medicine cabinets\n\r"); Print(MYVARS,"and decide to "); if(MYVARS->first_time_in_room_2==yes) { Print(MYVARS,"open a cabinet up."); } else { Print(MYVARS,"open another cabinet up."); } Print(MYVARS," While rifling through its contents\n\r"); if(MYVARS->first_time_in_room_2==yes) { Print(MYVARS,"you find a key!"); } else { if(MYVARS->Key[2]==no) //You don't have the key { Print(MYVARS,"you note a shiny object in one of the other cabinets! After\n\r"); Print(MYVARS,"look into the other cabinet, you see a key, just sitting there\n\r"); Print(MYVARS,"crying \"pick me up!!\""); } else { Print(MYVARS,"you find nothing of any value. Just some asprin and such...\n\r"); } } Print(MYVARS," Then you look around to see that there are are\n\rdoorless exits from this room to the North and South!"); MYVARS->first_time_in_room_2=no; } /////////////////////////////////////Room 1////////////////////////////////////////////// void Room1(struct SAVEVARS *MYVARS) { Print(MYVARS,"You are in a cold damp cave, however, you have no clue as to why.... To\n\rfigure "); Print(MYVARS,"out where you are, you will start to map each room. This will be\n\rcalled room "); printf("%d",MYVARS->room);//sadly, Print is unable to handle ints, floats, or chars (strings) Print(MYVARS,". There are rooms to the North and the East of this room.\n\r"); if(MYVARS->Key[1]==no) //You don't have the key { Print(MYVARS,"You notice a key in the corner, maybe you should pick it up..."); } else { Print(MYVARS,"As you scan the room, you see nothing of interest...."); } } /////////////////////////////////////////////Display Room/////////////////////////////// void Display_room(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 1://each number in the "case _" symbolizes the current room number Room1(MYVARS);//display the room break;//this exits out of the "switch/case statement" case 2: Room2(MYVARS); break; case 3: Room3(MYVARS); break; case 4: Room4(MYVARS); break; case 5: Room5(MYVARS); break; case 6: Room6(MYVARS); break; case 7: Room7(MYVARS); break; case 8: Room8(MYVARS); break; case 9: Room9(MYVARS); break; default: Print(MYVARS,"\n\rERROR! There is no room where you are!!!"); break; } } /////////////////////////////////////////////NowWhat/////////////////////////////// void NowWhat(struct SAVEVARS *MYVARS) { if(MYVARS->Died==yes){return;} if(MYVARS->last_action_not_move==yes) { printf("\n"); Display_room(MYVARS); MYVARS->last_action_not_move=no; } Print(MYVARS,"\n\n\rYou are in room "); printf("%d",MYVARS->room); Print(MYVARS,", now what do you wish to do? "); if(MYVARS->Died==yes){return;} scanf("%s",personsays);printf("\n"); if(!strcmp(personsays,quit)||!strcmp(personsays,quit1)) { MYVARS->Died=yes;//your dead! well actually you quit return;//exit out of this function. } if(!strcmp(personsays,use)) { Use(MYVARS); MYVARS->last_action_not_move=yes; return; } if(!strcmp(personsays,save)) { Save_file(MYVARS,SOURCEFILE); MYVARS->last_action_not_move=yes; return; } if(!strcmp(personsays,pickup)) { Pick_up(MYVARS); MYVARS->last_action_not_move=yes; return; } if(!strcmp(personsays,help)) { Help(MYVARS); MYVARS->last_action_not_move=yes; return; } if(!strcmp(personsays,load)) { Load_file(MYVARS,SOURCEFILE); MYVARS->last_action_not_move=yes; return; } if(!strcmp(personsays,north)||!strcmp(personsays,north2)) { Move_N(MYVARS); return; } if(!strcmp(personsays,south)||!strcmp(personsays,south2)) { Move_S(MYVARS); return; } if(!strcmp(personsays,east)||!strcmp(personsays,east2)) { Move_E(MYVARS); return; } if(!strcmp(personsays,west)||!strcmp(personsays,west2)) { Move_W(MYVARS); return; } //if you have gotten this far, you have not registered with any of the words that could //be used here, so it says it isn't a correct word! Print(MYVARS,"\n\rSorry, that is not a correct word!"); } ///////////////////////////////West///////////////////////////////////////////// void Move_W(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 4://each number in the "case _" symbolizes the current room number MYVARS->room=3;//this is the changed number break;//this exits out of the "switch/case statement" case 5: MYVARS->room=4; break; case 7: MYVARS->room=8; break; case 8: MYVARS->room=1; break; default: Print(MYVARS,"\n\rI'm sorry, but you can't go that way!\a\a\a\n\r");//\a makes an noise in MOST computers break; } Display_room(MYVARS); } ////////////////////////////////East//////////////////////////////////////////// void Move_E(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 1://each number in the "case _" symbolizes the current room number MYVARS->room=8;//this is the changed number break;//this exits out of the "switch/case statement" case 8: MYVARS->room=7; break; case 3: MYVARS->room=4; break; case 4: MYVARS->room=5; break; default: Print(MYVARS,"\n\rI'm sorry, but you can't go that way!\a\a\a\n\r");//\a makes an noise in MOST computers break; } Display_room(MYVARS); } ////////////////////////////////South//////////////////////////////////////////// void Move_S(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 2://each number in the "case _" symbolizes the current room number MYVARS->room=1;//this is the changed number break;//this exits out of the "switch/case statement" case 3: MYVARS->room=2; break; case 5: MYVARS->room=6; break; case 6: MYVARS->room=7; break; case 8: if(MYVARS->room_eight_door_open==yes) MYVARS->room=9; else Print(MYVARS,"\n\rHow do you go south?!?\n\r"); break; default: Print(MYVARS,"\n\rI'm sorry, but you can't go that way!\a\a\a\n\r");//\a makes an noise in MOST computers break; } Display_room(MYVARS); } //////////////////////////////North////////////////////////////////////////////// void Move_N(struct SAVEVARS *MYVARS) { switch(MYVARS->room) { case 1://each number in the "case _" symbolizes the current room number MYVARS->room=2;//this is the changed number break;//this exits out of the "switch/case statement" case 2: MYVARS->room=3; break; case 7: MYVARS->room=6; break; case 6: MYVARS->room=5; break; default: Print(MYVARS,"\n\rI'm sorry, but you can't go that way!\a\a\a\n\r");//\a makes an noise in MOST computers break; } Display_room(MYVARS); } ///////////////////////////Clock Speed///////////////////////////////////////////////// void Clockspeed(struct SAVEVARS *MYVARS) { Print(MYVARS,"Press 1 for slow text, 2 for fast text and 3 for ultra-fast text! "); scanf("%d", &MYVARS->Clock); printf("\n"); if(MYVARS->Clock>3||MYVARS->Clock<1) { printf("That isn't an option!\n\r"); Clockspeed(MYVARS); return; } printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); } ////////////////////////////////Color///////////////////////////////////////// void ChangeColor(struct SAVEVARS *MYVARS) { int multicolorcheck=0; if(MYVARS->color==0)//if you have random color on, it randomizes the color { MYVARS->color = rand()% 14; multicolorcheck=0;//allows the "do-while" loop to continue to be random... while keeping the color "0" saved for the moment } else { multicolorcheck=MYVARS->color;//so that after each char, the MYVARS->color will continue the same } switch(MYVARS->color)//which color do you want? 1=white, 2=yellow, etc. { case 1: textcolor(WHITE); break; case 2: textcolor(YELLOW); break; case 3: textcolor(GREEN); break; case 4: textcolor(CYAN); break; case 5: textcolor(RED); break; case 6: textcolor(MAGENTA); break; case 7: textcolor(BROWN); break; case 8: textcolor(LIGHTGRAY); break; case 9: textcolor(LIGHTMAGENTA); break; case 10: textcolor(LIGHTBLUE); break; case 11: textcolor(LIGHTGREEN); break; case 12: textcolor(LIGHTCYAN); break; case 13: textcolor(LIGHTRED); break; default: textcolor(LIGHTRED); //in case their is a glitch, I want to make sure the text is SOME color! break; } MYVARS->color=multicolorcheck;//so it it is "0" then it will change back to "0" //Otherwise, it will have no affect on the color! } ///////////////////////////////PRINT//////////////////// void Print(struct SAVEVARS *MYVARS, char *string) { unsigned long index=0; do{ ChangeColor(MYVARS);//What color do you use? wouldn't be needed if no multicolor! cprintf("%c", (int)string[index]);//prints one char. in the string DelayA(MYVARS); //slows down the print for each letter. }while(string[++index]!='\0');//when one Print has ended, it exits the print function //by the way.....'\0' symbolizes "end of line" /*You should note there are some limits to this program, such as it isn't possible to print NON-preset numbers... ie: Print(MYVARS,"enter a number! "); scanf("%d",&number"); // Print(MYVARS,"you entered- %d, however, this will not WORK!!!",number); printf("you entered- %d",number); ////////////////////////// while printf can accept print numbers and char. strings, Print(MYVARS,""); can't..... however, it is possible, or so I am told, but it would make programming for it a pain in the butt. */ } ///////////////////DELAY/////////////////////////////////// void DelayA(struct SAVEVARS *MYVARS) { int delay1; switch(MYVARS->Clock) { case 1: for(delay1=0;delay1<44;delay1++) { if(!kbhit())//if you hit a key, it will automatically finish printing the paragraph or sentence { delay(1);//note that delay sometimes doesn't work with all compilers. //if it doesn't, you can remove it and remove the "slow" print settings } else { return; } } break; case 2: for(delay1=0;delay1<24;delay1++) { if(!kbhit()) { delay(1); } else { return; } } break; case 3://if you have choosen 3, the program exits out EVERY time it prints a letter... while it causes a short //delay, it is SOO small, it is hard to notice. return; } } /////////////////////////////////////Text Color////////////////////// void TCOLOR(struct SAVEVARS *MYVARS) { MYVARS->color=0; Print(MYVARS,"0 ");MYVARS->color=0; Print(MYVARS,"i");MYVARS->color=0; Print(MYVARS,"s");MYVARS->color=0; Print(MYVARS," f");MYVARS->color=0; Print(MYVARS,"o");MYVARS->color=0; Print(MYVARS,"r");MYVARS->color=0; Print(MYVARS," R");MYVARS->color=0; Print(MYVARS,"a");MYVARS->color=0; Print(MYVARS,"i");MYVARS->color=0; Print(MYVARS,"n");MYVARS->color=0; Print(MYVARS,"b");MYVARS->color=0; Print(MYVARS,"o");MYVARS->color=0; Print(MYVARS,"w\n\r"); MYVARS->color=1; //textMYVARS->color(WHITE); Print(MYVARS,"1 is for White\n\r"); //textMYVARS->color(YELLOW); MYVARS->color=2; Print(MYVARS,"2 is for Yellow\n\r"); //textMYVARS->color(GREEN); MYVARS->color=3; Print(MYVARS,"3 is for Green\n\r"); //textMYVARS->color(CYAN); MYVARS->color=4; Print(MYVARS,"4 is for Cyan\n\r"); //textMYVARS->color(RED); MYVARS->color=5; Print(MYVARS,"5 is for Red\n\r"); //textMYVARS->color(MAGENTA); MYVARS->color=6; Print(MYVARS,"6 is for Magenta\n\r"); //textMYVARS->color(BROWN); MYVARS->color=7; Print(MYVARS,"7 is for Brown\n\r"); //textMYVARS->color(LIGHTGRAY); MYVARS->color=8; Print(MYVARS,"8 is for Light Gray\n\r"); //textMYVARS->color(LIGHTMAGENTA); MYVARS->color=9; Print(MYVARS,"9 is for Light Magenta\n\r"); //textMYVARS->color(LIGHTBLUE); MYVARS->color=10; Print(MYVARS,"10 is for Light Blue\n\r"); //textMYVARS->color(LIGHTGREEN); MYVARS->color=11; Print(MYVARS,"11 is for Light Green\n\r"); //textMYVARS->color(LIGHTCYAN); MYVARS->color=12; Print(MYVARS,"12 is for Light Cyan\n\r"); //textMYVARS->color(LIGHTRED); MYVARS->color=13; Print(MYVARS,"13 is for Light Red\n\r"); Print(MYVARS,"What color do you wish for? "); scanf("%d", &MYVARS->color);printf("\n"); } ///////////////////////Main///////////////////////////// void main() { SAVEVARS MYVARS;//this intializes all the structure called above... MYVARS is the "code name" of the structure. clrscr();//this deletes anything currently on the screen. /*Note that in void main, all intergers must be intialized by using a "." As in MYVARS._name_of_interger. In any other function you use "->" as in MYVARS->_name_of_interger.... I really don't FULLY understand why but it is just the way it is.... */ MYVARS.color=3;//it is best to intialize all intergers before the program starts. MYVARS.Clock=1; MYVARS.key_fall_in_room_5=no;//the key hasn't fallen in room 5 yet. MYVARS.Died=0;//0=not dead MYVARS.room=1;//you should always start in room 1. MYVARS.room_eight_door_open=no;//room eights door starts closed! MYVARS.first_time_in_room_7=yes;//yes=first time, no = not first time MYVARS.first_time_in_room_2=yes;//same as room 7 MYVARS.Key[1]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[2]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[3]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[4]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[5]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[6]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[7]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[8]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.Key[9]=0;//You don't get the keys until you have get them (duhh!)! MYVARS.game_completed=no;//You can't beat the game before you start MYVARS.opened_CD_saturn_in_room_3=no;//Guess..... Clockspeed(&MYVARS);//in main() you must intialize ALL MYVARS in functions with a & sign, //but in a program the & sign is not needed TCOLOR(&MYVARS); clrscr(); Title(&MYVARS); Room1(&MYVARS); do{//do what ever is contained with in the brackets....while Died doesn't equal 1 NowWhat(&MYVARS); }while(MYVARS.Died!=1);//!= means doesn't equal printf("\n\rThanks for Playing this game!");//sadly "Print(MYVARS""); doesn't work in main if(MYVARS.game_completed==yes) { Game_finished(&MYVARS); } else { printf("\n\n"); } Credits(&MYVARS); // Pause(); Pause1(); /*I guess this is a good time to describe "Pause" to you Pause will display a small message explaining that it requires you to press a key to continue. Pause1 on the otherhand, will not display a message, but still requires a key to be entered.... if you want you can comment out Pause and try Pause1 to see the differences for your self! */ }