Game Development Reference
In-Depth Information
Moving Through Rooms
Listing 10-19 updates the Game::RunGame method to store the user's selected option and call a new
UpdateOnOption method.
Listing 10-19. Updating Game::RunGame
void Game::RunGame()
{
InitializeRooms();
WelcomePlayer();
bool shouldEnd = false;
while (shouldEnd == false)
{
GivePlayerOptions();
string playerInput;
GetPlayerInput(playerInput);
PlayerOptions selectedOption = EvaluateInput(playerInput);
shouldEnd = selectedOption == PlayerOptions::Quit;
if (shouldEnd == false)
{
UpdateOnOption(selectedOption);
}
}
}
RunGame now stores the result from EvaluateInput and calls UpdateOnOption if the player has
not chosen to quit. Before I show you the code for UpdateOnOption we will look at the updated
GivePlayerOptions and EvaluateInput methods in Listing 10-20.
Listing 10-20. Updating GivePlayerOptions and EvaluateInput
void Game::GivePlayerOptions() const
{
cout << "What would you like to do? (Enter a corresponding number)"
<< endl << endl;
cout << "1: Go North" << endl << endl;
cout << "2: Go East" << endl << endl;
cout << "3: Go South" << endl << endl;
cout << "4: Go West" << endl << endl;
cout << "5: Quit" << endl << endl;
}
PlayerOptions Game::EvaluateInput(string& playerInput) const
{
PlayerOptions chosenOption = PlayerOptions::None;
 
Search WWH ::




Custom Search