Game Development Reference
In-Depth Information
void InitializeRooms();
void WelcomePlayer();
void GivePlayerOptions() const;
void GetPlayerInput(std::string& playerInput) const;
PlayerOptions EvaluateInput(std::string& playerInput);
public:
Game();
void RunGame();
};
There are four MoveOption instances, one QuitOption instance, and an array of Option pointers.
The constructor of the class is also new. Listing 11-12 shows the constructor for Game .
Listing 11-12. The Game Class Constructor
Game::Game()
: m_moveNorthOption(Room::JoiningDirections::North,
PlayerOptions::GoNorth,
"Go North")
, m_moveEastOption(Room::JoiningDirections::East,
PlayerOptions::GoEast,
"Go East")
, m_moveSouthOption(Room::JoiningDirections::South,
PlayerOptions::GoSouth,
"Go South")
, m_moveWestOption(Room::JoiningDirections::West,
PlayerOptions::GoWest,
"Go West")
, m_quitOption("Quit")
{
m_options[0] = dynamic_cast<Option*>(&m_moveNorthOption);
m_options[1] = dynamic_cast<Option*>(&m_moveEastOption);
m_options[2] = dynamic_cast<Option*>(&m_moveSouthOption);
m_options[3] = dynamic_cast<Option*>(&m_moveWestOption);
m_options[4] = dynamic_cast<Option*>(&m_quitOption);
}
The Game class constructor initializes the Option class objects and the array of pointers. Next you
need to update the Game::GivePlayerOptions method. You can see how this is done in Listing 11-13.
Listing 11-13. Updating Game::GivePlayerOptions
void Game::GivePlayerOptions() const
{
cout << "What would you like to do? (Enter a corresponding number)"
<< endl << endl;
for (unsigned int i = 0; i < m_numberOfOptions; ++i)
{
Option* option = m_options[i];
const unsigned int chosenOption = i + 1;
cout << chosenOption << ": " << option->GetOutputText() << endl << endl;
 
Search WWH ::




Custom Search