April 2017
Beginner to intermediate
394 pages
9h 16m
English
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); ...Read now
Unlock full access