//*******************************************
//* *
//* Mirrors of ELixia *
//* Start Date: 12/02/11 @ 08:31 pm *
//* End Date: ??/??/?? @ ??:?? ?? *
//* Creator: Aramil Daern of Elixia *
//* *
//*******************************************
//header file collection
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
usingnamespace std;
int state = 1;
void room1des();
void room1();
void help();
int main()
{
cout<<"Please do all typing in lowercase.\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 cube-like. ""There are four walls made out of what looks like pure stone with not a single crack. ""There is a chest in the center of the room. ""On the west wall there is a simple wooden door. ""Besides that there is the cot you were sleeping on.\n\n";
state = 2;
}
void room1()
{
string action;
staticbool 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();
}
elseif(action == "describe room")
{
state = 1;
}
elseif(!look_under_cot && action == "look under cot")
{
look_under_cot = true;
cout<<"You look under the cot and see something shiny. You reach for it and realize it's a key. You pick it up.\n";
key_found = true;
}
elseif(look_under_cot && action == "look under cot")
{
cout<<"You look under the cot again but find nothing.\n";
}
elseif(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";
}
elseif(!door1_opened && action == "open door")
{
door1_opened = true;
cout<<"You open the door and find yourself staring at a blank wall. There must be another way out.\n";
}
elseif(door1_opened && action == "close door")
{
cout<<"You close the door.\n";
door1_opened = false;
}
//This will eventually take you to the boss room
//All good games need easter eggs
elseif(door1_opened && action == "leave through stone wall")
{
cout<<"You see through the illusion of the wall and step through.\n";
exit(1);
}
elseif(door1_opened && key_found && !key_used && !chest_opened && action == "unlock chest")
{
cout<<"You unlock the chest and see the outline of a false panel appear at the bottom of the chest.\n";
chest_opened = true;
panel_discovered = true;
key_used = true;
}
elseif(chest_opened && action == "close chest")
{
cout<<"You shut the chest and pull out the key.\n";
chest_opened = false;
key_used = false;
}
elseif(chest_opened && panel_discovered && action == "move panel")
{
cout<<"You move the panel and discover a button under it.\n";
panel_moved = true;
}
elseif(panel_moved && chest_opened && action == "push button")
{
cout<<"You push the button and see a false door open up on the east wall.\n";
false_door_opened = true;
}
//This will eventually lead to to room two description
elseif(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-unlock [object]\n\t-open [object]\n\t-close [object]\n\t-leave [exit]\n";
}
Please change line 46 to this to make the page less wide:
46 47 48 49 50
cout<<"\nThis room is small and cube-like. ""There are four walls made out of what looks like pure stone with not a single crack. ""There is a chest in the center of the room. ""On the west wall there is a simple wooden door. ""Besides that there is the cot you were sleeping on.\n\n";
String literals concatenate when they have nothing between them, making them easy to split apart.
As for your mini rpg, I'd recommend a 2D array of function pointers and have another function specifically for understanding which command was entered and reacting to it.