April 2017
Beginner to intermediate
394 pages
9h 16m
English
The Strategy pattern is about encapsulating a set of behaviors and having the client control the behavior through an interface, instead of hardcoding the behavior into the client function itself. What this means is that we want the game object to be completely independent of the behavior it uses. Imagine that we want to give each enemy a different attack and flight AI. We could use the Strategy pattern instead of creating an inheritance tree:
class Enemy: public Unit { public: Enemy(void); virtual ~Enemy(void); virtual void Update(float dt); virtual void CollisionReaction(Object* pCollidedWith); protected: unsigned char m_color[4]; FlightAI* m_flight; AttackAI* m_attack; };
In this case, our client ...
Read now
Unlock full access