Game Development Reference
In-Depth Information
public:
Option(PlayerOptions chosenOption, const std::string& outputText)
: m_chosenOption(chosenOption)
, m_outputText(outputText)
{
}
void Option::SetOptionText(const std::string& optionText)
{
m_optionText = optionText;
}
const std::string& GetOutputText() const
{
return m_outputText;
}
PlayerOptions GetChosenOption() const
{
return m_chosenOption;
}
virtual bool Evaluate(const std::string& optionText, Player& player) = 0;
};
The Option class stores the PlayerOption value that it represents as well as the text that is output to
the player and a string to compare to the text the player enters. You can then derive specific classes
from Option , the MoveOption and QuitOption classes. Listing 11-9 shows the MoveOption class and
Listing 11-10 shows the QuitOption class.
Listing 11-9. The MoveOption Class
class MoveOption
: public Option
{
private:
Room::JoiningDirections m_directionToMove;
public:
MoveOption(Room::JoiningDirections joiningDirection,
PlayerOptions chosenOption,
const std::string& outputText)
: Option(chosenOption, outputText)
, m_directionToMove(joiningDirection)
{
}
virtual bool Evaluate(const std::string& optionText, Player& player);
};
 
Search WWH ::




Custom Search