Does anyone have any suggestions as to how I could better this code.(Not too fancy).
I'm supposed to use a switch statement. I think the concept isn't bad. But some things are off as far as my opitions displaying correcly.
#include <iostream>
using namespace std;
int main ()
{
char Direction;
int room;
cout << "*****************************************\n"
<< "* A Simple Text Based C++ Adventure Game*\n"
<< "*****************************************\n\n\n"
<< "At any given time you, the player can move north,\n"
<< "sout, east, and west by entering N, S, E, or W respectively.\n"
<< "When you enter a room the program will output a room description\n"
<< "and tell you what directions have doors available. If you select\n"
<< "a direction then you will move in that direction to a room adjacent\n"
<< "to where you are located. If you enter a direction where there is no\n"
<< "door you will be informed that the move is invalid.\n\n\n"
<< "You, the player will begin in room 1 and win the game when you reach room 7.\n\n\n";
cout << "You are now in Room 1.\n"
<< "Room 1 has a north door to room 2 and an east door to room 4.\n";
room = 1;
cout << "Enter a direction (N or E): ";
cin >> Direction;
switch (Direction)
{
case 'n':
case 'N':
if(room = 1)
{
cout << "You are now in Room 2.\n"
<< "Room 2 has an east door to room 3 and a south door to room 1\n"
<< "Enter a direction (E or S) ";
cin >> Direction;
room = 2;
}
if(room = 4)
{
cout << "You are now in Room 3.\n"
<< "Room 3 has an east door to room 6, a west door to room 2,\n"
<< "a north door to room 5, and a south door to room 4.\n"
<< "Enter a direction (E, W, N, or S) ";
cin >> Direction;
room = 3;
}
break;
case 's':
case 'S':
if (room = 6)
{
cout << "You are now in room 7.\n"
<< "YOU WIN THE GAME!!!!!\n";
room = 7;
}
break;
case 'e':
case 'E':
if(room = 1)
{
cout << "You are now in Room 4.\n"
<< "Room 4 has a north door to room 3 and a west door to room 1\n"
<< "Enter a direction (N or W) ";
cin >> Direction;
room = 4;
}
if ( room = 2)
{
room = 3;
}
if (room = 3)
{
room = 6;
cout << " You are now in room 6.\n"
<< "Room 6 has a south door to room 7\n"
<< "and a west door to room 3.\n"
<< "Enter a direction (W or S) ";
cin >> Direction;
}
break;
case 'w':
case 'W':
if(room = 6)
{
room = 3;
}
break;
default:
cout << "unknown room\n\n";
}
}