Text adventures

Could somebody please tell me if this code is any good to use?

//*******************************************
//* *
//* SteamPunk RPG *
//* Start Date: 22/02/14 @ 11:44 pm *
//* End Date: ??/??/?? @ ??:?? ?? *
//* Creator: Oscar Osborne *
//* *
//*******************************************

//header file collection
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>

using namespace std;

int state = 1;

void room1des();
void room1();
void help();

int main()
{
cout<<"Welcome to City of Steam BETA 0.1 [Please do all typing in lower case].\nYou wake up with no memory of who or where you are. You decide to look around.\n";

while(state != -1)
{
switch(state)
{
case 1:
room1des();
break;

case 2:
room1();
break;
}
}
}

void room1des()
{
cout<<"\nThis room is small and littered with furniture. "
"There are four walls made out of what looks like tattered brass. "
"There is a chest in the center of the room. "
"On the west wall there is a simple wooden door. "
"Besides that there are the rags you were sleeping on, which look quite suspicious.\n\n";
state = 2;
}

void room1()
{
string action;
static bool look_under_cot = false, key_found = false, key_used = false, chest_opened = false, door1_opened = false, panel_discovered = false, panel_moved = false, false_door_opened =false;

cout<<"What do you want to do (type \"help\" for a list of commands)?\n>";
getline (cin, action);

if(action == "help")
{
help();
}

else if(action == "describe room")
{
state = 1;
}

else if(!look_under_cot && action == "look under rags")
{
look_under_cot = true;
cout<<"It seems that there are an assortment of gears under the rags! You pick them up.\n";
key_found = true;
}

else if(look_under_cot && action == "look under cot")
{
cout<<"You look under the cot again but find nothing.\n";
}

else if(key_found && !key_used && !door1_opened && action == "unlock chest")
{
cout<<"You try to unlock the chest but there is something jamming the key hole.\n";
}

else if(!door1_opened && action == "open door")
{
door1_opened = true;
cout<<"there is a contraption on the door, it looks like a mechanical puzzle! There must be another way out.\n";
}

else if(door1_opened && action == "leave door")
{
cout<<"You leave the door.\n";
door1_opened = false;
}

//This will eventually take you to the boss room
//All good games need easter eggs
else if(door1_opened && action == "place gears")
{
cout<<"You place the gears in the correct order and it opens, Huzzah! There is a chest in the room.\n";

}

else if(door1_opened && key_found && !key_used && !chest_opened && action == "open chest")
{
cout<<"You unlock the chest and see a Tesla generator (A product of the industrial movement!) with an 'on' switch.\n";
chest_opened = true;
panel_discovered = true;
key_used = true;
}

else if(chest_opened && action == "leave item")
{
cout<<"You shut the chest and pull out the key.\n";
chest_opened = false;
key_used = false;
}

else if(chest_opened && panel_discovered && action == "turn on mechanism")
{
cout<<"You turn it on and power surges across the room! The walls begin to close in on you, but a passageway has opened in the main room! You must run, and be quick about it too! \n";
panel_moved = true;
}

else if(panel_moved && chest_opened && action == "run")
{
cout<<"You run and scurry out of the room, END OF CHAPTER ONE.\n";
false_door_opened = true;
}

//This will eventually lead to to room two description
else if(false_door_opened && action == "leave room")
{
cout<<"You leave the room.\n";
state = 3;
}

else
{
cout<<"That is not a valid command.\n";
}
}

void help()
{
cout<<"Commands:\n\t-look under [object]\n\t-open [object]\n\t-unlock [object]\n\t-close [object]\n\t-leave [exit]\n";
}
What is it expected to do?
it should run a text adventure, the revised version is in the next text box.
Last edited on
kbw, here is a revised version, it should run a text adventure.

//*******************************************
//* *
//* SteamPunk RPG *
//* Start Date: 22/02/14 @ 11:44 pm *
//* End Date: ??/??/?? @ ??:?? ?? *
//* Creator: Oscar Osborne *
//* *
//*******************************************

//header file collection
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>

using namespace std;

int state = 1;

void room1des();
void room1();
void help();

int main()
{
cout<<"Welcome to City of Steam BETA 0.1 [Please do all typing in lower case].\nYou wake up with no memory of who or where you are. You decide to look around.\n";

while(state != -1)
{
switch(state)
{
case 1:
room1des();
break;

case 2:
room1();
break;
}
}
}

void room1des()
{
cout<<"\nThis room is small and littered with furniture. "
"There are four walls made out of what looks like tattered brass. "
"There is a chest in the center of the room. "
"Besides that there are the rags you were sleeping on, which look quite suspicious.\n\n";
state = 2;
}

void room1()
{
string action;
static bool look_under_cot = false, key_found = false, key_used = false, chest_opened = false, door1_opened = false, panel_discovered = false, panel_moved = false, false_door_opened =false;

cout<<"What do you want to do (type \"help\" for a list of commands)?\n>";
getline (cin, action);

if(action == "help")
{
help();
}

else if(action == "describe room")
{
state = 1;
}

else if(!look_under_cot && action == "inspect rags")
{
look_under_cot = true;
cout<<"It seems that there are an assortment of gears under the rags! You pick them up, as you do you notice a door, that was previously shrouded in shadow.\n";
key_found = true;
}

else if(look_under_cot && action == "inspect rags")
{
cout<<"You look under the cot again but find nothing.\n";
}

else if(key_found && !key_used && !door1_opened && action == "open chest")
{
cout<<"You try to unlock the chest but there is something jamming the key hole.\n";
}

else if(!door1_opened && action == "open door")
{
door1_opened = true;
cout<<"there is a contraption on the door, it looks like a mechanical puzzle! There must be another way out.\n";
}

else if(door1_opened && action == "leave door")
{
cout<<"You leave the door.\n";
door1_opened = false;
}

//This will eventually take you to the boss room
//All good games need easter eggs
else if(door1_opened && action == "place gears")
{
cout<<"You place the gears in the correct order and it opens, Huzzah! There is a chest in the room.\n";

}

else if(door1_opened && key_found && !key_used && !chest_opened && action == "open chest")
{
cout<<"You unlock the chest and see a Tesla generator (A product of the industrial movement!) with an 'on' switch.\n";
chest_opened = true;
panel_discovered = true;
key_used = true;
}

else if(chest_opened && action == "leave item")
{
cout<<"You shut the chest and pull out the key.\n";
chest_opened = false;
key_used = false;
}

else if(chest_opened && panel_discovered && action == "turn on")
{
cout<<"You turn it on and power surges across the room! The walls begin to close in on you, but a passageway has opened in the main room! You must run, and be quick about it too! \n";
panel_moved = true;
}

else if(panel_moved && chest_opened && action == "run")
{
cout<<"You run and scurry out of the room, END OF CHAPTER ONE.\n";
false_door_opened = true;
}

//This will eventually lead to to room two description
else if(false_door_opened && action == "leave room")
{
cout<<"You leave the room.\n";
state = 3;
}

else
{
cout<<"That is not a valid command.\n";
}
}

void help()
{
cout<<"Commands:\n\t-inspect [object]\n\t-open [object]\n\t-attack [object]\n\t-close [object]\n\t-leave [exit]\n";
}
Topic archived. No new replies allowed.