Life entity (base class). Written for OOP Review.
Dependencies: armoured_vehicle enemy player
life_entity.h@1:0b3582b2b45f, 2011-04-01 (annotated)
- Committer:
- Nakor
- Date:
- Fri Apr 01 01:30:46 2011 +0000
- Revision:
- 1:0b3582b2b45f
- Parent:
- 0:cee9139ed454
Documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nakor | 0:cee9139ed454 | 1 | #ifndef _LIFEENTITY_ |
Nakor | 0:cee9139ed454 | 2 | #define _LIFEENTITY_ |
Nakor | 0:cee9139ed454 | 3 | |
Nakor | 0:cee9139ed454 | 4 | #include "mbed.h" |
Nakor | 0:cee9139ed454 | 5 | |
Nakor | 0:cee9139ed454 | 6 | /** Base life entity class. |
Nakor | 0:cee9139ed454 | 7 | * |
Nakor | 0:cee9139ed454 | 8 | * This class is inherited by all life entities (user, enemies, anything you can think of that |
Nakor | 0:cee9139ed454 | 9 | * is supposed to live). |
Nakor | 0:cee9139ed454 | 10 | * |
Nakor | 0:cee9139ed454 | 11 | * Example: |
Nakor | 0:cee9139ed454 | 12 | * @code |
Nakor | 0:cee9139ed454 | 13 | * // Create a pointer to a life_entity object. |
Nakor | 0:cee9139ed454 | 14 | * life_entity *currentEnemy; |
Nakor | 0:cee9139ed454 | 15 | * |
Nakor | 0:cee9139ed454 | 16 | * int main() |
Nakor | 0:cee9139ed454 | 17 | * { |
Nakor | 0:cee9139ed454 | 18 | * // Use the pointer to create a new armoured_vehicle (derived class) |
Nakor | 0:cee9139ed454 | 19 | * currentEnemy = new armoured_vehicle(user); |
Nakor | 0:cee9139ed454 | 20 | * } |
Nakor | 0:cee9139ed454 | 21 | * @endcode |
Nakor | 0:cee9139ed454 | 22 | */ |
Nakor | 0:cee9139ed454 | 23 | class life_entity |
Nakor | 0:cee9139ed454 | 24 | { |
Nakor | 0:cee9139ed454 | 25 | |
Nakor | 0:cee9139ed454 | 26 | public: |
Nakor | 0:cee9139ed454 | 27 | /** Base life entity class constructor. |
Nakor | 0:cee9139ed454 | 28 | * |
Nakor | 0:cee9139ed454 | 29 | * This class is inherited by all life entities (user, enemies, anything you can think of that |
Nakor | 0:cee9139ed454 | 30 | * is supposed to live). |
Nakor | 0:cee9139ed454 | 31 | * |
Nakor | 0:cee9139ed454 | 32 | * Example: |
Nakor | 0:cee9139ed454 | 33 | * @code |
Nakor | 0:cee9139ed454 | 34 | * // Create a pointer to a life_entity object. |
Nakor | 0:cee9139ed454 | 35 | * life_entity *currentEnemy; // Life entity object |
Nakor | 0:cee9139ed454 | 36 | * |
Nakor | 0:cee9139ed454 | 37 | * int main() |
Nakor | 0:cee9139ed454 | 38 | * { |
Nakor | 0:cee9139ed454 | 39 | * // Use the pointer to create a new armoured_vehicle (derived class) |
Nakor | 0:cee9139ed454 | 40 | * currentEnemy = new armoured_vehicle(user); |
Nakor | 0:cee9139ed454 | 41 | * } |
Nakor | 0:cee9139ed454 | 42 | * @endcode |
Nakor | 0:cee9139ed454 | 43 | */ |
Nakor | 0:cee9139ed454 | 44 | life_entity(); |
Nakor | 0:cee9139ed454 | 45 | |
Nakor | 0:cee9139ed454 | 46 | /** Base life entity class destructor. |
Nakor | 0:cee9139ed454 | 47 | * |
Nakor | 0:cee9139ed454 | 48 | * This class is inherited by all life entities (user, enemies, anything you can think of that |
Nakor | 0:cee9139ed454 | 49 | * is supposed to live). |
Nakor | 0:cee9139ed454 | 50 | * |
Nakor | 0:cee9139ed454 | 51 | * Example: |
Nakor | 0:cee9139ed454 | 52 | * @code |
Nakor | 0:cee9139ed454 | 53 | * // Create a pointer to a life_entity object. |
Nakor | 0:cee9139ed454 | 54 | * life_entity *currentEnemy; |
Nakor | 0:cee9139ed454 | 55 | * |
Nakor | 0:cee9139ed454 | 56 | * int main() |
Nakor | 0:cee9139ed454 | 57 | * { |
Nakor | 0:cee9139ed454 | 58 | * // Use the pointer to create a new armoured_vehicle (derived class) |
Nakor | 0:cee9139ed454 | 59 | * currentEnemy = new armoured_vehicle(user); |
Nakor | 0:cee9139ed454 | 60 | * |
Nakor | 0:cee9139ed454 | 61 | * delete currentEnemy; |
Nakor | 0:cee9139ed454 | 62 | * } |
Nakor | 0:cee9139ed454 | 63 | * @endcode |
Nakor | 0:cee9139ed454 | 64 | */ |
Nakor | 0:cee9139ed454 | 65 | virtual ~life_entity(); |
Nakor | 0:cee9139ed454 | 66 | |
Nakor | 0:cee9139ed454 | 67 | /** Get number of life entities currently spawned. |
Nakor | 0:cee9139ed454 | 68 | * |
Nakor | 0:cee9139ed454 | 69 | * |
Nakor | 0:cee9139ed454 | 70 | * Example: |
Nakor | 0:cee9139ed454 | 71 | * @code |
Nakor | 0:cee9139ed454 | 72 | * char count = getLifeEntityCount(); |
Nakor | 0:cee9139ed454 | 73 | * @endcode |
Nakor | 0:cee9139ed454 | 74 | */ |
Nakor | 0:cee9139ed454 | 75 | char getLifeEntityCount(); |
Nakor | 0:cee9139ed454 | 76 | |
Nakor | 0:cee9139ed454 | 77 | /** Returns the current status of the entity's life points. |
Nakor | 0:cee9139ed454 | 78 | * |
Nakor | 0:cee9139ed454 | 79 | * |
Nakor | 0:cee9139ed454 | 80 | * Example: |
Nakor | 0:cee9139ed454 | 81 | * @code |
Nakor | 0:cee9139ed454 | 82 | * int lifePoints = getHealth(); |
Nakor | 0:cee9139ed454 | 83 | * @endcode |
Nakor | 0:cee9139ed454 | 84 | */ |
Nakor | 0:cee9139ed454 | 85 | int getHealth(); |
Nakor | 0:cee9139ed454 | 86 | |
Nakor | 0:cee9139ed454 | 87 | /** Get the current level of the entity. |
Nakor | 0:cee9139ed454 | 88 | * |
Nakor | 0:cee9139ed454 | 89 | * No error checking is performed. If you wish to use this you |
Nakor | 0:cee9139ed454 | 90 | * should consider adding a check or two. |
Nakor | 0:cee9139ed454 | 91 | * The level is currently stored in a char, and therefore maxes |
Nakor | 0:cee9139ed454 | 92 | * out at 255 (0xFF). |
Nakor | 0:cee9139ed454 | 93 | * |
Nakor | 0:cee9139ed454 | 94 | * Example: |
Nakor | 0:cee9139ed454 | 95 | * @code |
Nakor | 0:cee9139ed454 | 96 | * char currentLevel = getLevel(); |
Nakor | 0:cee9139ed454 | 97 | * @endcode |
Nakor | 0:cee9139ed454 | 98 | */ |
Nakor | 0:cee9139ed454 | 99 | char getLevel(); |
Nakor | 0:cee9139ed454 | 100 | |
Nakor | 0:cee9139ed454 | 101 | /** Entity rolls for damage. |
Nakor | 0:cee9139ed454 | 102 | * |
Nakor | 0:cee9139ed454 | 103 | * All entities use this to roll for damage (against thier opponent). |
Nakor | 0:cee9139ed454 | 104 | * |
Nakor | 0:cee9139ed454 | 105 | * Example: |
Nakor | 0:cee9139ed454 | 106 | * @code |
Nakor | 0:cee9139ed454 | 107 | * int roll = rollDamage(); |
Nakor | 0:cee9139ed454 | 108 | * @endcode |
Nakor | 0:cee9139ed454 | 109 | */ |
Nakor | 0:cee9139ed454 | 110 | int rollDamage(); |
Nakor | 0:cee9139ed454 | 111 | |
Nakor | 0:cee9139ed454 | 112 | /** Take damage from apponent. |
Nakor | 0:cee9139ed454 | 113 | * |
Nakor | 0:cee9139ed454 | 114 | * Derived classes set this up on specific to thier needs. |
Nakor | 0:cee9139ed454 | 115 | * |
Nakor | 0:cee9139ed454 | 116 | * @param roll The damage roll to be passed in (most likely from rollDamage()). |
Nakor | 0:cee9139ed454 | 117 | * |
Nakor | 0:cee9139ed454 | 118 | */ |
Nakor | 0:cee9139ed454 | 119 | virtual void takeDamage(int) { }; |
Nakor | 0:cee9139ed454 | 120 | |
Nakor | 0:cee9139ed454 | 121 | |
Nakor | 0:cee9139ed454 | 122 | protected: |
Nakor | 0:cee9139ed454 | 123 | /** |
Nakor | 0:cee9139ed454 | 124 | * Entity health variable (int). |
Nakor | 0:cee9139ed454 | 125 | */ |
Nakor | 0:cee9139ed454 | 126 | int _health; |
Nakor | 0:cee9139ed454 | 127 | |
Nakor | 0:cee9139ed454 | 128 | /** |
Nakor | 0:cee9139ed454 | 129 | * Entity level variable (char). |
Nakor | 0:cee9139ed454 | 130 | */ |
Nakor | 0:cee9139ed454 | 131 | char _level; |
Nakor | 0:cee9139ed454 | 132 | |
Nakor | 0:cee9139ed454 | 133 | /** |
Nakor | 0:cee9139ed454 | 134 | * Static entity count variable (int). |
Nakor | 0:cee9139ed454 | 135 | */ |
Nakor | 0:cee9139ed454 | 136 | static int lifeEntityCount; |
Nakor | 0:cee9139ed454 | 137 | |
Nakor | 0:cee9139ed454 | 138 | }; |
Nakor | 0:cee9139ed454 | 139 | |
Nakor | 0:cee9139ed454 | 140 | #endif |