Game Development Reference
In-Depth Information
Now you can see the very clean template method call. This simple call will call the
OnQuit
method on
every object that has been added as an observer on the
QuitOption
. That's our next step: The
Game
class is updated to inherit from
QuitObserver
in Listing 23-12.
Listing 23-12. The
Game
Class
QuitObserver
class Game
: public EventHandler
, public QuitObserver
{
private:
static const unsigned int m_numberOfRooms = 4;
using Rooms = std::array<Room::Pointer, m_numberOfRooms>;
Rooms m_rooms;
Player m_player;
Option::Pointer m_attackDragonOption;
Option::Pointer m_attackOrcOption;
Option::Pointer m_moveNorthOption;
Option::Pointer m_moveEastOption;
Option::Pointer m_moveSouthOption;
Option::Pointer m_moveWestOption;
Option::Pointer m_openSwordChest;
Option::Pointer m_quitOption;
Sword m_sword;
Chest m_swordChest;
using Enemies = std::vector<Enemy::Pointer>;
Enemies m_enemies;
bool m_playerQuit{ false };
void InitializeRooms();
void WelcomePlayer();
void GivePlayerOptions() const;
void GetPlayerInput(std::stringstream& playerInput) const;
void EvaluateInput(std::stringstream& playerInput);
public:
Game();
~Game();
void RunGame();
virtual void HandleEvent(const Event* pEvent);
// From QuitObserver
virtual void OnQuit();
};