Game Development Reference
In-Depth Information
Listing 11-10. The QuitOption Class
class QuitOption
: public Option
{
private:
bool m_shouldQuit;
public:
QuitOption(const std::string& outputText)
: Option(PlayerOptions::Quit, outputText)
, m_shouldQuit(false)
{
}
bool ShouldQuit() const { return m_shouldQuit; }
virtual bool Evaluate(const std::string& optionText, Player& player);
};
bool QuitOption::Evaluate(const std::string& optionText, Player& player)
{
m_shouldQuit = m_optionText.compare(optionText) == 0;
if (m_shouldQuit == true)
{
std::cout << "You have chosen to quit!" << std::endl << std::endl;
}
return m_shouldQuit;
}
The QuitOption determines whether the player has chosen to quit the game. Listing 11-11 shows
how you can add these options to the Game class.
Listing 11-11. Adding the New Options to Game
class Game
{
private:
static const unsigned int m_numberOfRooms = 4;
Room m_rooms[m_numberOfRooms];
Player m_player;
MoveOption m_moveNorthOption;
MoveOption m_moveEastOption;
MoveOption m_moveSouthOption;
MoveOption m_moveWestOption;
QuitOption m_quitOption;
static const unsigned int m_numberOfOptions = 5;
Option* m_options[m_numberOfOptions];
 
Search WWH ::




Custom Search