Game Development Reference
In-Depth Information
AttackEnemyOption m_attackDragonOption;
AttackEnemyOption m_attackOrcOption;
MoveOption m_moveNorthOption;
MoveOption m_moveEastOption;
MoveOption m_moveSouthOption;
MoveOption m_moveWestOption;
OpenChestOption m_openSwordChest;
QuitOption m_quitOption;
Sword m_sword;
Chest m_swordChest;
Enemy m_dragon;
Enemy m_orc;
bool m_playerQuit{ false };
void InitializeRooms();
void WelcomePlayer();
void GivePlayerOptions() const;
void GetPlayerInput(std::stringstream& playerInput) const;
void EvaluateInput(std::stringstream& playerInput);
public:
Game();
void RunGame();
virtual void HandleEvent(const Event* pEvent);
};
The three bold lines are the only changes to the class definition. It is now derived from the
EventHandler interface and overrides the HandleEvent method. There is also a bool , m_playerQuit ,
used to store whether the player has chosen to quit, which is initialized to false .
Listing 21-22 shows the changes that are needed in the Game::RunGame method.
Listing 21-22. Updating Game::RunGame
void Game::RunGame()
{
new EventManager();
RegisterEvent(QuitEvent);
AttachEvent(QuitEvent, this);
InitializeRooms();
WelcomePlayer();
 
Search WWH ::




Custom Search