Text adventure

I'm almost done with my "Text Adventure" game, but the last thing I need to worry about is getting my game to end once I hit the exit door. I tried break but that doesn't seem to work; how about while statements?

cout << "\n\nPick a door to enter by typing the direction it is in ";
cout << "(N/E/S/W): ";
cin >> direction;
cout << endl;
if (align == 0)
{
if (direction == 'N')
{
monsterRoom(banana, orange, monster);
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else if (direction == 'S')
{
genieRoom(banana, orange);
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else if (direction == 'E')
{
drawPicture();
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else if (direction == 'W')
{
ExitRoom(banana, orange, score);
break;
}
else
{
cout << "\n\nPick a door to enter by typing the direction it ";
cout << "is in (N/E/S/W): ";
cin >> direction;
}
}
if (align == 1)
{
if (direction == 'N')
{
ExitRoom(banana, orange, score);
break;
}
else if (direction == 'S')
{
monsterRoom(banana, orange, monster);
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else if (direction == 'E')
{
genieRoom(banana, orange);
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else if (direction == 'W')
{
drawPicture();
cout << "\n\n";
cout << name << ", you are in a room with 4 doors." << endl;
cout << "You are carrying " << banana << " bananas and ";
cout << orange << " oranges." << endl;
cout << endl;
}
else
{
cout << "\n\nPick a door to enter by typing the direction it ";
cout << "is in (N/E/S/W): ";
cin >> direction;
}
}
return 0;
}
First:
Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/


break; is not required here. It applies to loop and switch only.
After the if is done the function (whatever it is) just ends. if the function is main then the program exits.


if you're in a [deep] recursion you can use exit(0):

http://www.cplusplus.com/reference/cstdlib/exit/
Furthermore, I can't seem to get the game to repeat once I enter a door or enter a character other than N S E or W.
Post all of your code again in the code tags to make it easier to read.

I don't think that's all of your code since I can't seem to find where you have defined, or declared, the variable "align".
Last edited on
Topic archived. No new replies allowed.