#include <process.h> // exit#include <dos.h> // sound, nosound, delay#include <stdio.h> // putchar#include <conio.h> // getch, clrscr, gotoxy, _setcursortype, putch#include <fstream.h> // lotsa stuff, auto-iostream.h!!!#include <ctype.h> // tolower#include <stdlib.h> // randconst unsigned short int BACKSPACE=8;enum boolean { false, true};struct GameVars { unsigned short int location; int score; boolean sword; boolean lamp; boolean intropaper; boolean spork; boolean b0, b1, b2, b3;};GameVars v;char *getFileName(void);char *getstr(void);void newgame(void);void oldgame(void);void click(void);void begin(void);void DownStairs(void);void Inv(void);void Quit(void);void GetRank(void);void NormCmds(char j[]);void Outside1(void);void Outside2(void);void main(void) { _setcursortype(_NOCURSOR); char choice; int i; boolean newc=true, oldc=false, quitc=false; clrscr(); gotoxy(35, 2); cout << "[gamename]\n"; gotoxy(1, 8); putch(218); for (i=1; i<78; i++) putch(196); putch(191); gotoxy(30, 10); cout << "M A I N M E N U\n"; gotoxy(31, 13); cout << "Start a new game\n"; gotoxy(31, 14); cout << "Restore an old game\n"; gotoxy(31, 15); cout << "Quit\n"; gotoxy(1, 17); putch(192); for (i=1; i<78; i++) putch(196); putch(217); gotoxy(32, 19); cout << "Arrow keys move\n"; gotoxy(33, 20); cout << "Enter selects\n"; gotoxy(33, 21); cout << "Esc backs out\n"; for (i=9; i<=16; i++) { gotoxy(1, i); putch(179); gotoxy(79, i); putch(179); } gotoxy(28, 13); putch(196); putch(16); while (true) { choice=getch(); if (choice==72) { // up arrow if (newc) { newc=false; quitc=true; } else if (oldc) { oldc=false; newc=true; } else if (quitc) { quitc=false; oldc=true; } } else if (choice==80) { // down arrow if (newc) { newc=false; oldc=true; } else if (oldc) { oldc=false; quitc=true; } else if (quitc) { quitc=false; newc=true; } } else if (choice=='\r') { if (newc) newgame(); else if (oldc) oldgame(); else if (quitc) break; } else if (choice==27) { // Esc key break; } gotoxy(28, 13); cout << " "; gotoxy(28, 14); cout << " "; gotoxy(28, 15); cout << " "; if (newc) { gotoxy(28, 13); putch(196); putch(16); } else if (oldc) { gotoxy(28, 14); putch(196); putch(16); } else if (quitc) { gotoxy(28, 15); putch(196); putch(16); } } _setcursortype(_NORMALCURSOR);}char *getFileName(void) { static char buffer[128]; int i=0; char letter=NULL; while ((i<127) && (letter!='\r')) { letter=getch(); if (letter==BACKSPACE) { if (i>0) { buffer[--i]=NULL; putchar(BACKSPACE); putchar(' '); putchar(BACKSPACE); } else click(); } else if (letter != '\r') { buffer[i++]=letter; putchar(letter); } } buffer[i]=NULL; if (buffer[0]=='\0') { buffer[0]='S'; buffer[1]='A'; buffer[2]='V'; buffer[3]='E'; buffer[4]='1'; buffer[5]='.'; buffer[6]='S'; buffer[7]='A'; buffer[8]='V'; buffer[9]='\0'; } return (buffer);}void newgame(void) { int g; clrscr(); _setcursortype(_NORMALCURSOR); // INITIALIZING: { v.score=0; v.sword=v.lamp=v.spork=v.intropaper=false; v.b0=v.b1=false; } cout << "\n\n\n\n"; cout << "[gamename]\n"; cout << "Copyright (c) 2000\n"; cout << "Version 0.0b, Revision 1.\n\n\n\n"; begin();}void oldgame(void) { char *filename; _setcursortype(_NORMALCURSOR); clrscr(); gotoxy(33, 2); cout << "-- Old Game --"; gotoxy(1, 5); cout << "Enter the filename of the game to load\n\ (Default is SAVE1.SAV): "; filename=getFileName(); cout << filename;}void click(void) { sound(1000); delay(20); nosound();}void begin(void) { v.location=0; if (!v.b0) { cout << "\n\nUpstairs\n\nYou are in the bedroom of your house. Stairs lead down to the main room.\n"; if (v.intropaper==false) cout << "A piece of paper lies on the floor."; v.b0=true; } while (1) { int i=0; cout << "\n\n]"; char j[78]; char letter=NULL; while ((i<127) && (letter!='\r')) { letter=getch(); if (letter==BACKSPACE) { if (i>0) { j[--i]=NULL; putchar(BACKSPACE); putchar(' '); putchar(BACKSPACE); } else click(); } else if (letter != '\r') { j[i++]=letter; putchar(letter); } } j[i]=NULL; if (j[0]=='\0') { cout << "\nExcuse me?"; i=rand()%15; if (i==12) cout << "\nThe house settles with a creak."; continue; } else NormCmds(j); i=rand()%15; if (i==4) cout << "\nThe house settles with a creak."; }}void Inv(void) {cout << "\n-- Inventory --\n";if (v.intropaper==true) cout << "\n * Piece of Paper";if (v.lamp==true) cout << "\n * Lamp";if (v.sword==true) cout << "\n * Sword";if (v.spork==true) cout << "\n * Spork";if (!v.intropaper && !v.lamp && !v.sword && !v.spork) cout << "\nYou are not carrying anything.";}void Quit(void) {char c;cout << "\nYour score is " << v.score << " out of a possible -=128=-.\nThis gives you the rank of ";GetRank();putchar('.');cout << "\nAre you sure you want to quit (Y is affirmative) ]";c=getche();if (c=='y' || c=='Y') exit(0);else cout << "\nOk.";}void GetRank(void) {if (v.score==0) cout << "Newbie";else if (v.score<5) cout << "Beginner";else if (v.score<20) cout << "Novice";else if (v.score<30) cout << "Adventurer";else if (v.score<40) cout << "Skilled Adventurer";else if (v.score<55) cout << "Ranger";else if (v.score<70) cout << "Skilled Ranger";else if (v.score<90) cout << "Master Adventurer";else if (v.score<110) cout << "Elite Adventurer";else cout << "Lord of All Adventurers";}void NormCmds(char j[]) { if (tolower(j[0])=='q' && j[1]=='\0') Quit(); else if (tolower(j[0])=='i' && j[1]=='\0') Inv(); else if (j[0]=='b' && j[1]=='u' && j[2]=='r' && j[3]=='p' && j[4]=='\0') cout << "\nYou burp obscenely."; else if (j[0]=='b' && j[1]=='e' && j[2]=='l' && j[3]=='c' && j[4]=='h' && j[5]=='\0') cout << "\nYou burp obscenely."; else if (j[0]=='i' && j[1]=='n' && j[2]=='v') { if (j[3]=='\0') Inv(); else if (j[3]=='e' && j[4]=='n' && j[5]=='t' && j[6]=='o' && j[7]=='r' && j[8]=='y' && j[9]=='\0') Inv(); else cout << "\nYour words totally confuse me."; } else if (j[0]=='q' && j[1]=='u' && j[2]=='i' && j[3]=='t') Quit(); else if (j[0]=='l' && j[1]=='o' && j[2]=='o' && j[3]=='k' && j[4]==' ' && j[5]=='a' && j[6]=='t' && j[7]==' ') { if (j[8]=='p' && j[9]=='a' && j[10]=='p' && j[11]=='e' && j[12]=='r' && j[13]=='\0') { if (v.intropaper==true) { cout << "\nThe paper says:\n"; cout << "\nWelcome to [gamename]! blah blah blah blah"; cout << "\nblah blah blah blah blah blah blah blah!!!"; } // end if paper=true else { if (v.location==0) cout << "\nYou can\'t read the paper from here. You\'ll have to pick it up."; else cout << "\nYou can\'t see any paper here!"; } // end else }// end if j[8], .. = paper else if (j[8]=='p' && j[9]=='i' && j[10]=='e' && j[11]=='c' && j[12]=='e' && j[13]==' ' && j[14]=='o' && j[15]=='f' && j[16]==' ' && j[17]=='p' && j[18]=='a' && j[19]=='p' && j[20]=='e' && j[21]=='r' && j[22]=='\0') { if (v.intropaper==true) { cout << "\nThe paper says:\n"; cout << "\nWelcome to [gamename]! blah blah blah blah"; cout << "\nblah blah blah blah blah blah blah blah!!!"; } // end if paper=true else { if (v.location==0) cout << "\nYou can\'t read the paper from here. You\'ll have to pick it up."; else cout << "\nYou can\'t see any piece of paper here!"; } // end else } // end if j[8], .. = piece of paper else if (tolower(j[8])=='l' && tolower(j[9])=='a' && tolower(j[10])=='m' && tolower(j[11])=='p' && j[12]=='\0') { if (v.lamp==true) cout << "\nThe lamp looks new and has lots of life still in it."; else { if (v.location==1) cout << "\nThe lamp looks ripe for the picking, sitting in front of you."; else cout << "\nYou can\'t see any lamp here!"; } // end else } // end if j[8], .. = lamp /////////// more items else cout << "\nYour words totally confuse me."; } // end if start = look at else if (tolower(j[0])=='n' && j[1]=='\0') { if (v.location == 2) { cout << "\nDownstairs"; DownStairs(); } else if (v.location == 3) { cout << "\nThe Large Cavern"; Outside1(); } else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='s' && j[1]=='\0') { if (v.location == 1) { cout << "\nThe Large Cavern"; Outside1(); } else if (v.location == 2) { cout << "\nThe Chamber"; Outside2(); } else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='w' && j[1]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='e' && j[1]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='n' && tolower(j[1])=='w' && j[2]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='n' && tolower(j[1])=='e' && j[2]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='s' && tolower(j[1])=='w' && j[2]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='s' && tolower(j[1])=='e' && j[2]=='\0') { if (v.location == 9999); else cout << "\nYou can\'t go that way!"; } else if ((tolower(j[0])=='u' && j[1]=='\0') || (tolower(j[0])=='u' && tolower(j[1])=='p' && j[2]=='\0')) { if (v.location == 1) { cout << "\nUpstairs"; begin(); } else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='d' && (j[1]=='\0' || (tolower(j[1])=='o' && tolower(j[2])=='w' && tolower(j[3])=='n' && j[4]=='\0'))) { if (v.location == 0) { cout << "\nDownstairs"; DownStairs(); } else cout << "\nYou can\'t go that way!"; } else if (tolower(j[0])=='l' && (j[1]=='\0' || (tolower(j[1])=='o' && tolower(j[2])=='o' && tolower(j[3])=='k' && j[4]=='\0'))) { if (v.location == 0) { cout << "\n\nYou are in the bedroom of your house. Stairs lead down to the main room.\n"; if (!v.intropaper) cout << "A piece of paper lies on the floor."; } else if (v.location == 1) { cout << "\nYou are in the main room of your house. There is a table in the middle\n"; cout << "of the room. There is a door on the southern wall."; if (!v.lamp) cout << "\nA lamp is sitting on the table."; } else if (v.location == 2) { cout << "\n\nYou are in a large cavern. Stalactites hang from the dull grey ceiling.\n"; cout << "Your house is to the north, and the cave continues to the south."; } else if (v.location == 3) { cout << "\n\nYou have entered a enormous open chamber in the cave. "; if (!v.spork) { cout << "You spot something\nlying on the floor. Walking up, you realize ..."; cout << "\nIt\'s not a spoon. It\'s not a fork! It\'s the legendary SPORK!"; } cout << "\nThe cave continues to the north and south."; } } else if (j[0]=='g' && j[1]=='e' && j[2]=='t') { if (j[3]==' ') { if (j[4]=='p' && j[5]=='a' && j[6]=='p' && j[7]=='e' && j[8]=='r' && j[9]=='\0') { if (v.location==0) { if (v.intropaper) cout << "\nYou already have that!"; else { cout << "\nYou pick up the piece of paper."; v.intropaper=true; } // end else } // end if location=0 else cout << "\nYou can\'t see any paper here."; } // end if j[4], .. = paper else if (j[4]=='p' && j[5]=='i' && j[6]=='e' && j[7]=='c' && j[8]=='e' && j[9]==' ' && j[10]=='o' && j[11]=='f' && j[12]==' ' && j[13]=='p' && j[14]=='a' && j[15]=='p' && j[16]=='e' && j[17]=='r' && j[18]=='\0') { if (v.location==0) { if (v.intropaper) cout << "\nYou already have that!"; else { cout << "\nYou pick up the piece of paper."; v.intropaper=true; } // end else } // end if location=0 else cout << "\nYou can\'t see any piece of paper here."; } // end if j[4], .. = piece of paper else if (tolower(j[4])=='l' && tolower(j[5])=='a' && tolower(j[6])=='m' && tolower(j[7])=='p' && j[8]=='\0') { if (v.location==1) { if (v.lamp) cout << "\nYou already have that!"; else { cout << "\nYou grab the lamp.\nNOTE: The lamp is always on!"; v.lamp=true; } // end else } // end if location=1 else cout << "\nYou can\'t see any lamp here."; } // end if j[4], .. = lamp else if (j[4]=='a' && j[5]=='l' && j[6]=='l' && j[7]=='\0') { if (v.location==0) { if (v.intropaper) cout << "\nThere is nothing here to get."; else { cout << "\nYou pick up the piece of paper."; v.intropaper=true; } // end else } // end if location=0 else if (v.location==1) { if (v.lamp) cout << "\nThere is nothing here to get."; else { cout << "\nYou grab the lamp.\nNOTE: The lamp is always on!"; v.lamp=true; } // end else } // end if location=1 ///// other locations } // end if j[4], .. = all } // end if j[3]=" " (space) else if (j[3]=='\0') { if (v.location==0) { if (v.intropaper) cout << "\nThat was an incomplete sentence!"; else { cout << "\n (piece of paper)"; cout << "\nYou pick up the piece of paper."; v.intropaper=true; } // end else } // end if location=0 else if (v.location==1) { if (v.lamp) cout << "\nThat was an incomplete sentence!"; else { cout << "\n (lamp)"; cout << "\nYou grab the lamp.\nNOTE: The lamp is always on!"; v.lamp=true; } // end else } // end if location=1 ///// other locations else cout << "\nThat was an incomplete sentence!"; } // end if j[3]='\0' else cout << "\nYour words totally confuse me."; } // end if j[0], .. = get} // end functionvoid DownStairs(void) { v.location=1; if (!v.b1) { cout << "\n\nYou are in the main room of your house. There is a table in the middle\n"; cout << "of the room. There is a door on the southern wall."; if (!v.lamp) cout << "\nA lamp is sitting on the table."; v.b1=true; } while (1) { cout << "\n\n]"; char j[128]; int i=0; char letter=NULL; while ((i<127) && (letter!='\r')) { letter=getch(); if (letter==BACKSPACE) { if (i>0) { j[--i]=NULL; putchar(BACKSPACE); putchar(' '); putchar(BACKSPACE); } else click(); } else if (letter != '\r') { j[i++]=letter; putchar(letter); } } j[i]=NULL; if (j[0]=='\0') { cout << "\nExcuse me?"; i=rand()%15; if (i==12) cout << "\nThe house settles with a creak."; continue; } else NormCmds(j); i=rand()%15; if (i==4) cout << "\nThe house settles with a creak."; }}void Outside1(void) { v.location=2; if (!v.b2) { cout << "\n\nYou are in a large cavern. Stalactites hang from the dull grey ceiling.\n"; cout << "Your house is to the north, and the cave continues to the south."; v.b2=true; } while (1) { cout << "\n\n]"; char j[128]; int i=0; char letter=NULL; while ((i<127) && (letter!='\r')) { letter=getch(); if (letter==BACKSPACE) { if (i>0) { j[--i]=NULL; putchar(BACKSPACE); putchar(' '); putchar(BACKSPACE); } else click(); } else if (letter != '\r') { j[i++]=letter; putchar(letter); } } j[i]=NULL; if (j[0]=='\0') { cout << "\nExcuse me?"; continue; } else NormCmds(j); }}void Outside2(void) { v.location=3; if (!v.b3) { cout << "\n\nYou have entered a enormous open chamber in the cave. "; if (!v.spork) { cout << "You spot something\nlying on the floor. Walking up, you realize ..."; cout << "\nIt\'s not a spoon. It\'s not a fork! It\'s the legendary SPORK!"; } cout << "\nThe cave continues to the north and south."; v.b3=true; } while (1) { cout << "\n\n]"; char j[128]; int i=0; char letter=NULL; while ((i<127) && (letter!='\r')) { letter=getch(); if (letter==BACKSPACE) { if (i>0) { j[--i]=NULL; putchar(BACKSPACE); putchar(' '); putchar(BACKSPACE); } else click(); } else if (letter != '\r') { j[i++]=letter; putchar(letter); } } j[i]=NULL; if (j[0]=='\0') { cout << "\nExcuse me?"; continue; } else NormCmds(j); }}