I am programming a game in C++, the problem is, it isn't taking me to each room or giving me the room descriptions and also when I choose to take an item, it won't take the item.
I have been staring at this code and my eyes hurt. Please help.
#include <iostream>
#include <string>
using namespace std;
int iFlag=0x00000000;
#define DOOR_NORTH 0x00000001
#define DOOR_SOUTH 0x00000002
#define DOOR_WEST 0x00000004
#define DOOR_EAST 0x00000008
#define BOOTS 0x00000010
#define COMPASS 0x00000020
#define ACCESS_CODE 0x00000040
#define ARMY_SUIT 0x00000080
#define MOUSE 0x00000100
#define BUTTERCUP 0x00000200
#define MOCKING_JAY 0x00000400
#define LADY 0x00000800
#define TRACKER_JACKER 0x00001000
#define SPIDERS 0x00002000
#define GORG 0x00004000
#define MONKEY 0x00008000
#define DEADLY 0x00010000
#define DANGEROUS 0x00020000
#define CAUTION 0x00040000
#define FRIENDLY 0x00080000
void BuildRooms(unsigned int rooms[][4]);
void DescribeRoomContents(int roomDesc, int row, int col);
void DescribeRoom00_00();
void DescribeRoom00_01();
void DescribeRoom00_02();
void DescribeRoom00_03();
void DescribeRoom00_04();
void DescribeRoom01_00();
void DescribeRoom02_00();
void DescribeRoom03_00();
void DescribeRoom04_00();
void DescribeRoom01_01();
void DescribeRoom02_02();
void DescribeRoom03_03();
void DescribeRoom04_04();
void DescribeRoom01_04();
void DescribeRoom01_05();
void DescribeRoom01_06();
int TakeItem(unsigned int rooms[4][4], int row, int col, string Object);
int main()
{
string cmdVerb; string cmdObj; int iRow;
int iCol;
int iNumRows;
int iNumCols;
int idx;
int bQuitGame;
int iPlayer=0;
int endRow=2;
int endCol=2;
unsigned int panem[4][4];
for(int row=0; row<4;row++)
for(int col=0; col<4;col++)
panem[row][col]=0;
BuildRooms(panem);
iRow=0;
iCol=0;
iNumRows=4;
iNumCols=4;
idx=0;
cout<<"HOW TO PLAY"<<endl;
cout<<" "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" It is your job to locate 4 treasure items located within the walls"<<endl; cout<<"of District 13. Navigate through all sixteen rooms by using cardinal direction."<<endl;
cout<<" "<<endl; cout<<" Each room obtains a door, that door is found by correctly giving the cardinal"<<endl; cout<<" direction to enter that are. For example, to get into the first room you would"<<endl;
cout<<"choose North, to get into room 2 you would choose Southeast and so forth."<<endl;
cout<<" "<<endl; cout<<" Some rooms will have creatures, some good some bad, avoid getting too close"<<endl; cout<<"to any of the genetically morphed animals, they are bad news. Some rooms will"<<endl;
cout<<"also contain useless items. You need to disregard those items and only choose"<<endl;
cout<<"the treasure items."<<endl;
cout<<" "<<endl; cout<<" After successfully gathering all 4 items,you need"<<endl; cout<<"to find your way back to the elevator and escape District 13 before"<<endl;
cout<<"President Coin catches you. Good luck, and remember to hurry!"<<endl;
bQuitGame=false;
while(!bQuitGame)
{
cout<<"\nWhat do you want to do?"; cin>>cmdVerb>>cmdObj;
cout<<endl;
idx=0;
while((unsigned)idx<cmdverb.length())>
{
cmdVerb[idx]=toupper(cmdVerb[idx]);
idx++;
}
idx=0;
while((unsigned)idx<cmdobj.length())>
{
cmdObj[idx]=toupper(cmdObj[idx]);
idx++;
}
cout<<"Command is:"<<cmdVerb<<" "<<cmdObj<<endl;
if(cmdVerb=="GO")
{
cout<<"command verb is GO"<<endl;
if(cmdObj=="NORTH")
{
if(panem[iRow][iCol]&DOOR_NORTH)
{
iRow--; DescribeRoomContents(panem[iRow][iCol], iRow,iCol);
}
else
cout<<"There is no door to the NORTH"<<endl;
}
else if(cmdObj=="SOUTH")
{
if(panem[iRow][iCol]&DOOR_SOUTH)
{
iRow++; DescribeRoomContents(panem[iRow][iCol], iRow,iCol);
}
else
cout<<"There is no door to the SOUTH"<<endl;
cout<<"Direction is South"<<endl;
}
else if(cmdObj=="WEST")
{
if(panem[iRow][iCol]&DOOR_WEST)
{
iCol--; DescribeRoomContents(panem[iRow][iCol], iRow,iCol);
}
else
cout<<"There is no door to the WEST"<<endl;
cout<<"Direction is West"<<endl;
}
else if (cmdObj=="EAST")
{
if(panem[iRow][iCol]&DOOR_EAST)
{
iCol++; DescribeRoomContents(panem[iRow][iCol], iRow,iCol);
}
else
cout<<"There is no door to the EAST"<<endl;
cout<<"Direction is East"<<endl;
}
else
{
cout<<" I don't understand GO"<<cmdObj<<endl;
}
if((endRow==iRow)&& (endCol==iCol)) {
if((iPlayer & ACCESS_CODE)&&
(iPlayer & COMPASS)&&
(iPlayer & BOOTS)&&
(iPlayer & ARMY_SUIT))
{
cout<<"\n\nYou now have all the items to go to the elevator and leave PANEM.\n\n";
cout<<"Congratulations Player, you have now obtained all four"<<endl;
cout<<"treasure items; the Access Code, Boots, Compass and Army Suit."<<endl;
cout<<"The game is now over."<<endl;
bQuitGame=true; }
}
else if (cmdVerb=="TAKE")
{
if (cmdObj=="ACCESS_CODE")
{
int takeVal= TakeItem(panem,iRow,iCol, cmdObj);
if(takeVal)
{
iPlayer|= takeVal;
cout<<" You are now carrying the " <<cmdObj<<endl;
}
else
cout<<" You cannot take the "<<cmdObj<<" from this location."<<endl;
}
if (cmdObj=="BOOTS")
{
int takeVal= TakeItem(panem,iRow,iCol, cmdObj);
if(takeVal)
{
iPlayer|= takeVal;
cout<<" You are now carrying the " <<cmdObj<<endl;
}
else
cout<<" You cannot take the "<<cmdObj<<" from this location."<<endl;
}
if (cmdObj=="ARMY_SUIT")
{
int takeVal= TakeItem(panem,iRow,iCol, cmdObj);
if(takeVal)
{
iPlayer|= takeVal;
cout<<" You are now carrying the " <<cmdObj<<endl;
}
else
cout<<" You cannot take the "<<cmdObj<<" from this location."<<endl;
}
if (cmdObj=="COMPASS")
{
int takeVal= TakeItem(panem,iRow,iCol, cmdObj);
if(takeVal)
{
iPlayer|= takeVal;
cout<<" You are now carrying the " <<cmdObj<<endl;
}
else
cout<<" You cannot take the "<<cmdObj<<" from this location."<<endl;
}
}
else if (cmdVerb=="QUIT")
{
if (cmdObj=="GAME")
{
cout<<"Command object is game"<<endl;
}
else
{
cout<<"I don't understand"<<cmdVerb<<""<<cmdObj<<endl;
}
}
else
{
cout<<"I don't understand"<<endl;
}
}
}
return 0;
}
void DescribeRoom00_04()
{
cout<<"This is the cafeteria. Lunch is not being served at this time, the only thing in the"<<endl;
cout<<"room besides you is an empty cafeteria tray. The room is "<<endl;
cout<<" very large and lined with multiple tables."<<endl;
}
void DescribeRoom01_00()
{
cout<<" You have stumbled into the clothing closet. The room"<<endl;
cout<<"is small and lined with grey suits that are the required"<<endl;
cout<<"attire of all who live in District 13"<<endl;
}
void DescribeRoom02_00()
{
cout<<"This is President Coin’s room. Normally this room is off limits but"<<endl;
cout<<" President Coin appears to have left the door open."<<endl;
cout<<"Her dog Lady is lounging on the floor."<<endl;
}
void DescribeRoom03_00()
{
cout<<"This is the weapons room. The room is huge and filled"<<endl;
cout<<"with guns and knives and killing machines. You notice a long"<<endl;
cout<<"line if spiders eerily crawling across the barrel of a gun."<<endl;
}
void DescribeRoom04_00()
{
cout<<"This is the storage room, the room is mostly empty except for an empty box."<<endl;
cout<<" The room is regular in sized. Made of stone and of course no windows."<<endl;
cout<<"There is a small mouse that runs across your toes."<<endl;
}
void DescribeRoom01_01()
{
cout<<"You have arrived in the Holding Room where the disobedient are sent"<<endl;
cout<<"It appears, since the room is empty, that everyone is on their best behavior"<<endl;
}
void DescribeRoom02_02()
{
cout<<"This room seems to have come out of thin air, it is large and filled with piles"<<endl;
cout<<"of papers. In the corner you spot a Monkey, best not stay here long"<<endl;
}
void DescribeRoom00_03()
{
cout<<"Now you are in the History room. The room Is small and filled with"<<endl;
cout<<"desks for students. There are history books lined in the bookshelf and"<<endl;
cout<<" apparently some tracker jackers have made their way in the room with you"<<endl;
}
void DescribeRoom03_03()
{
cout<<"This is the command center. The room has dozens of computer"<<endl;
cout<<"screens monitoring District 13. A broken compass lays in front of you"<<endl;
}
void DescribeRoom04_04()
{
cout<<"This is the English room, lined with student desks and tons of dictionarys"<<endl;
cout<<"along with Englsih books. Jabber jays flock in the room above your head"<<endl;
}
void DescribeRoom01_04()
{
cout<<"You arrive in the conference room, again to find no one, the room is empty"<<endl;
cout<<" the only thing that is there is a long table where meetings are held"<<endl;
}
void DescribeRoom01_05()
{
cout<<"Now you have reached the door to the elevator, if only you could get"<<endl;
cout<<"inside you could escape from the wretched place."<<endl;
}
void DescribeRoom01_06()
{
cout<<" You are now in the target practice room. This room is like a jumbo sized"<<endl;
cout<<"school gymnasium. Except instead of having basketball goals, there are"<<endl;
cout<<"dart boards and targets."<<endl;
}
void BuildRooms(unsigned int rooms[][4])
{
rooms[0][0]=DOOR_EAST|DOOR_SOUTH;
rooms[0][1]=DOOR_EAST|DOOR_NORTH;
rooms[0][2]=DOOR_WEST|DOOR_NORTH|DOOR_SOUTH|MOUSE|CAUTION|ARMY_SUIT;
rooms[0][3]=DOOR_NORTH|DOOR_SOUTH|LADY|ACCESS_CODE;
rooms[1][0]=DOOR_WEST|DOOR_NORTH|SPIDERS|DEADLY;
rooms[1][1]=DOOR_WEST|DOOR_EAST|TRACKER_JACKER|DEADLY;
rooms[1][2]=DOOR_NORTH|DOOR_SOUTH|DOOR_EAST;
rooms[1][3]=DOOR_NORTH|DOOR_SOUTH;
rooms[1][4]=DOOR_WEST|DOOR_SOUTH|DOOR_EAST;
rooms[2][0]=DOOR_EAST|DOOR_SOUTH|MOCKING_JAY|FRIENDLY;
rooms[2][1]=DOOR_NORTH|DOOR_WEST|BUTTERCUP|FRIENDLY;
rooms[2][2]=DOOR_NORTH|DOOR_SOUTH|GORG|DEADLY|COMPASS;
rooms[2][3]=DOOR_EAST|BOOTS|MONKEY|CAUTION;
}
void DescribeRoomContents(int roomDesc, int row, int col)
{
switch (row)
{
case 0:
switch(col)
{
case 0:
DescribeRoom00_03();
break;
case 2:
DescribeRoom00_04();
break;
case 3:
DescribeRoom01_00();
break;
case 4:
DescribeRoom02_00();
break;
case 5:
DescribeRoom03_00();
break;
case 6:
DescribeRoom04_00();
break;
case 7:
DescribeRoom01_01();
break;
case 8:
DescribeRoom02_02();
break;
case 9:
DescribeRoom03_03();
break;
case 10:
DescribeRoom04_04();
break;
case 11:
DescribeRoom01_04();
break;
case 12:
DescribeRoom01_05();
break;
case 13:
DescribeRoom01_06();
break;
}
}
if(roomDesc & MONKEY)
cout<<"You see a mutant monkey lurking in the corner"<<endl;
if(roomDesc & TRACKER_JACKER)
cout<<"You see a swarm of Tracker Jackers ready to attack"<<endl;
if(roomDesc & SPIDERS)
cout<<"You have stumbled across a pack of spiders.\n";
if(roomDesc & GORG)
cout<<"Gorg stands guarding the door, he will kill before he lets you through.\n";
if(roomDesc & BUTTERCUP)
cout<<" What is that disgusting looking creature? Oh it is just Buttercup, poor cat is hideous.\n";
if(roomDesc & LADY)
cout<<" Lady, President Coins dog is almost as lazy as she is.\n";
if(roomDesc & MOCKING_JAY)
cout<<"You spot in the distance a Mocking Jay, what a beautiful creature.\n";
if(roomDesc & MOUSE)
cout<<"Ugh another mouse, those awful little squeaky creatures.\n";
if(roomDesc & DEADLY)
cout<<"This creature is Deadly RUN!\n";
if(roomDesc & CAUTION)
cout<<"This creature could be dangerous.\n";
if(roomDesc & DANGEROUS)
cout<<"This creature is Dangerous, be very careful.\n";
if(roomDesc & FRIENDLY)
cout<<"This creature is harmless.\n";
if(roomDesc & ARMY_SUIT)
cout<<" You see the army sui!\n";
if(roomDesc & COMPASS)
cout<<"You spot the compass in the corner.\n";
if(roomDesc & ACCESS_CODE)
cout<<"Could that be the access code?\n";
if(roomDesc & BOOTS)
cout<<"ah, a pair of boots perfect!\n";
if(roomDesc & DOOR_NORTH)
cout<<"There is a door to the North.\n";
if(roomDesc & DOOR_SOUTH)
cout<<"There is a door to the South.\n";
if(roomDesc & DOOR_WEST)
cout<<"There is a door to the West.\n";
if(roomDesc & DOOR_EAST)
cout<<"There is a door to the East.\n";
}
int TakeItem(unsigned int rooms [4][4], int row, int col, string Object)
{
if((Object=="ACCESS_CODE")&&(rooms[row][col]& ACCESS_CODE))
{
rooms[row][col]^=ACCESS_CODE;
return ACCESS_CODE;
}
else if((Object=="COMPASS")&&(rooms[row][col]& COMPASS))
{
rooms[row][col]^=COMPASS;
return COMPASS;
}
else if ((Object=="ARMY_SUIT")&&(rooms[row][col]& ARMY_SUIT))
{
rooms[row][col]^=ARMY_SUIT;
return ARMY_SUIT;
}
else if ((Object=="BOOTS")&&(rooms[row][col]& BOOTS))
{
rooms[row][col]^=BOOTS;
return BOOTS;
}
return 0;
}