The Observers

For this example, we have the three Observers that we mentioned before. Two are related to displaying the health of the Player in different ways; the other is used for quitting when the health of the Player is zero or less:

//Used to quit the game when the "game", when the player's health //is less than or equal to 0 class StageLogic : public Observer { public:   StageLogic (Subject* pSubject);   bool IsQuitting(void) const;   ~StageLogic(void);   virtual void Update(float currentHealth, float maxHealth); private:   bool     m_isQuitting;   Subject* m_pSubject; };  //Used to Color the player health bar based on the how full it is class PlayerHealthBar : public Observer { public:   PlayerHealthBar(Subject* pSubject);  ~PlayerHealthBar(void); ...

Get Game Development Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.