Game Development Reference
In-Depth Information
std::ostringstream chosenOptionString;
chosenOptionString << chosenOption;
option->SetOptionText(chosenOptionString.str());
}
}
The GivePlayerOptions method loops over the array of Option pointers, displays the options that
the user can select for each option, and sets the option text on the Option object. This method now
does not have to be changed as we add new options to the option array. The user input option
will automatically update as we change the array and the output text that we enter into the Option
constructors. The EvaluateInput method also gets an update in Listing 11-14.
Listing 11-14. The EvaluateInput Method
PlayerOptions Game::EvaluateInput(string& playerInput)
{
PlayerOptions chosenOption = PlayerOptions::None;
for (unsigned int i = 0; i < m_numberOfOptions; ++i)
{
Option* option = m_options[i];
bool handled = option->Evaluate(playerInput, m_player);
if (handled == true)
{
chosenOption = option->GetChosenOption();
break;
}
}
if (chosenOption == PlayerOptions::None)
{
cout << "I do not recognize that option, try again!" << endl << endl;
}
return chosenOption;
}
The EvaluateInput method has been simplified. It now also loops over the Option array and calls
Evaluate on each Option object. The last method to get an update is RunGame in Listing 11-15.
Listing 11-15. The RunGame Method
void Game::RunGame()
{
InitializeRooms();
WelcomePlayer();
bool shouldEnd = false;
 
Search WWH ::




Custom Search