April 2017
Beginner to intermediate
394 pages
9h 16m
English
When using composition, this is a strong HAS-A relationship, and this is when a class contains one or more instances of another class. Unlike aggregation, these instances are not created on their own but, instead, are created in the constructor of the class and then destroyed by its destructor. Put into layman's terms, they can't exist separately from the whole.
In this case, we have created some new properties for the Enemy class, adding in combat skills that it can use, as in the Pokémon series. In this case, for every one enemy, there are four skills that the enemy will be able to have:
class AttackSkill { public: void UseAttack(void); private: int damage; float cooldown; }; class Enemy { public: void GetHealth(void) ...Read now
Unlock full access