Player class. Written for OOP Review. Derived from life_entity.

Dependents:   life_entity

Committer:
Nakor
Date:
Fri Apr 01 01:30:26 2011 +0000
Revision:
1:2548417420a3
Parent:
0:7c89d9ec2d76
Documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nakor 0:7c89d9ec2d76 1 #ifndef _PLAYERENTITY_
Nakor 0:7c89d9ec2d76 2 #define _PLAYERENTITY_
Nakor 0:7c89d9ec2d76 3
Nakor 0:7c89d9ec2d76 4 #include "mbed.h"
Nakor 0:7c89d9ec2d76 5 #include "life_entity.h"
Nakor 0:7c89d9ec2d76 6
Nakor 0:7c89d9ec2d76 7 #define DEBUG_PLAYER 0x01
Nakor 0:7c89d9ec2d76 8
Nakor 0:7c89d9ec2d76 9
Nakor 1:2548417420a3 10 /** Player class derived from life_entity.
Nakor 1:2548417420a3 11 *
Nakor 1:2548417420a3 12 * This class is derived from life_entity.
Nakor 1:2548417420a3 13 *
Nakor 1:2548417420a3 14 * Example:
Nakor 1:2548417420a3 15 * @code
Nakor 1:2548417420a3 16 *
Nakor 1:2548417420a3 17 * // Create a new player object.
Nakor 1:2548417420a3 18 * player *user = new player();
Nakor 1:2548417420a3 19 *
Nakor 1:2548417420a3 20 * int main()
Nakor 1:2548417420a3 21 * {
Nakor 1:2548417420a3 22 * // Get the user's level (for example)
Nakor 1:2548417420a3 23 * char playerLevel = user->getLevel();
Nakor 1:2548417420a3 24 * }
Nakor 1:2548417420a3 25 * @endcode
Nakor 1:2548417420a3 26 */
Nakor 0:7c89d9ec2d76 27 class player : public life_entity
Nakor 0:7c89d9ec2d76 28 {
Nakor 0:7c89d9ec2d76 29
Nakor 0:7c89d9ec2d76 30 public:
Nakor 0:7c89d9ec2d76 31
Nakor 1:2548417420a3 32 /** Player class constructor.
Nakor 1:2548417420a3 33 *
Nakor 1:2548417420a3 34 * This class is derived from life_entity.
Nakor 1:2548417420a3 35 *
Nakor 1:2548417420a3 36 * Example:
Nakor 1:2548417420a3 37 * @code
Nakor 1:2548417420a3 38 *
Nakor 1:2548417420a3 39 * // Create a new player object.
Nakor 1:2548417420a3 40 * player *user = new player();
Nakor 1:2548417420a3 41 *
Nakor 1:2548417420a3 42 * int main()
Nakor 1:2548417420a3 43 * {
Nakor 1:2548417420a3 44 * // Get the user's level (for example)
Nakor 1:2548417420a3 45 * char playerLevel = user->getLevel();
Nakor 1:2548417420a3 46 * }
Nakor 1:2548417420a3 47 * @endcode
Nakor 1:2548417420a3 48 */
Nakor 0:7c89d9ec2d76 49 player();
Nakor 0:7c89d9ec2d76 50
Nakor 1:2548417420a3 51 /** Get the number of experience points the player currently has.
Nakor 1:2548417420a3 52 *
Nakor 1:2548417420a3 53 * Example:
Nakor 1:2548417420a3 54 * @code
Nakor 1:2548417420a3 55 * // Create a new player object.
Nakor 1:2548417420a3 56 * player *user = new player();
Nakor 1:2548417420a3 57 *
Nakor 1:2548417420a3 58 * int main()
Nakor 1:2548417420a3 59 * {
Nakor 1:2548417420a3 60 * // Get the user's xp
Nakor 1:2548417420a3 61 * unsigned long int xp = user->getExperience();
Nakor 1:2548417420a3 62 * }
Nakor 1:2548417420a3 63 * @endcode
Nakor 1:2548417420a3 64 */
Nakor 0:7c89d9ec2d76 65 unsigned long int getExperience();
Nakor 0:7c89d9ec2d76 66
Nakor 1:2548417420a3 67 /** Get the number player's current level.
Nakor 1:2548417420a3 68 *
Nakor 1:2548417420a3 69 * Example:
Nakor 1:2548417420a3 70 * @code
Nakor 1:2548417420a3 71 * // Create a new player object.
Nakor 1:2548417420a3 72 * player *user = new player();
Nakor 1:2548417420a3 73 *
Nakor 1:2548417420a3 74 * int main()
Nakor 1:2548417420a3 75 * {
Nakor 1:2548417420a3 76 * // Get the user's level
Nakor 1:2548417420a3 77 * char playerLevel = user->getLevel();
Nakor 1:2548417420a3 78 * }
Nakor 1:2548417420a3 79 * @endcode
Nakor 1:2548417420a3 80 */
Nakor 0:7c89d9ec2d76 81 char getLevel();
Nakor 0:7c89d9ec2d76 82
Nakor 1:2548417420a3 83 /** Check to see if the player is ready to level up.
Nakor 1:2548417420a3 84 *
Nakor 1:2548417420a3 85 * Compare the player's current experience with the amount
Nakor 1:2548417420a3 86 * of experience required to reach the next level.
Nakor 1:2548417420a3 87 * If enough experience is present, level up the player.
Nakor 1:2548417420a3 88 *
Nakor 1:2548417420a3 89 * Example:
Nakor 1:2548417420a3 90 * @code
Nakor 1:2548417420a3 91 * // Create a new player object.
Nakor 1:2548417420a3 92 * player *user = new player();
Nakor 1:2548417420a3 93 *
Nakor 1:2548417420a3 94 * int main()
Nakor 1:2548417420a3 95 * {
Nakor 1:2548417420a3 96 * // Check for level up
Nakor 1:2548417420a3 97 * user->isLevelUp();
Nakor 1:2548417420a3 98 * }
Nakor 1:2548417420a3 99 * @endcode
Nakor 1:2548417420a3 100 */
Nakor 0:7c89d9ec2d76 101 void isLevelUp();
Nakor 0:7c89d9ec2d76 102
Nakor 1:2548417420a3 103 /** Add experience points (and apply rest health).
Nakor 1:2548417420a3 104 *
Nakor 1:2548417420a3 105 * Add experience points for the win and calculate
Nakor 1:2548417420a3 106 * bonus health from 'rest'.
Nakor 1:2548417420a3 107 *
Nakor 1:2548417420a3 108 * Example:
Nakor 1:2548417420a3 109 * @code
Nakor 1:2548417420a3 110 * // Create a new player object.
Nakor 1:2548417420a3 111 * player *user = new player();
Nakor 1:2548417420a3 112 *
Nakor 1:2548417420a3 113 * int main()
Nakor 1:2548417420a3 114 * {
Nakor 1:2548417420a3 115 * // Add experience points to player
Nakor 1:2548417420a3 116 * user->addExperience();
Nakor 1:2548417420a3 117 * }
Nakor 1:2548417420a3 118 * @endcode
Nakor 1:2548417420a3 119 */
Nakor 0:7c89d9ec2d76 120 void addExperience();
Nakor 0:7c89d9ec2d76 121
Nakor 1:2548417420a3 122 /** Display player experience ramp.
Nakor 1:2548417420a3 123 *
Nakor 1:2548417420a3 124 * Display the amount of experience required
Nakor 1:2548417420a3 125 * for each level.
Nakor 1:2548417420a3 126 *
Nakor 1:2548417420a3 127 * Example:
Nakor 1:2548417420a3 128 * @code
Nakor 1:2548417420a3 129 * // Create a new player object.
Nakor 1:2548417420a3 130 * player *user = new player();
Nakor 1:2548417420a3 131 *
Nakor 1:2548417420a3 132 * int main()
Nakor 1:2548417420a3 133 * {
Nakor 1:2548417420a3 134 * // Print experience ramp
Nakor 1:2548417420a3 135 * user->displayExpRamp();
Nakor 1:2548417420a3 136 * }
Nakor 1:2548417420a3 137 * @endcode
Nakor 1:2548417420a3 138 */
Nakor 0:7c89d9ec2d76 139 void displayExpRamp();
Nakor 0:7c89d9ec2d76 140
Nakor 1:2548417420a3 141 /** Take damage from apponent.
Nakor 1:2548417420a3 142 *
Nakor 1:2548417420a3 143 * This applies the enemy's damage roll to the player's health after a dodge roll
Nakor 1:2548417420a3 144 * is performed.
Nakor 1:2548417420a3 145 *
Nakor 1:2548417420a3 146 * @param roll The damage roll to be passed in (most likely from rollDamage()).
Nakor 1:2548417420a3 147 *
Nakor 1:2548417420a3 148 * Example:
Nakor 1:2548417420a3 149 * @code
Nakor 1:2548417420a3 150 * player *user = new player();
Nakor 1:2548417420a3 151 * life_entity *currentEnemy;
Nakor 1:2548417420a3 152 *
Nakor 1:2548417420a3 153 * int main()
Nakor 1:2548417420a3 154 * {
Nakor 1:2548417420a3 155 * // Use the pointer to create a new armoured_vehicle (derived class)
Nakor 1:2548417420a3 156 * currentEnemy = new enemy(user);
Nakor 1:2548417420a3 157 *
Nakor 1:2548417420a3 158 * // Enemy rolls for damage
Nakor 1:2548417420a3 159 * int roll = currentEnemy->rollDamage();
Nakor 1:2548417420a3 160 * // Player takes the hit
Nakor 1:2548417420a3 161 * user->takeDamage(roll);
Nakor 1:2548417420a3 162 * }
Nakor 1:2548417420a3 163 * @endcode
Nakor 1:2548417420a3 164 */
Nakor 0:7c89d9ec2d76 165 virtual void takeDamage(int roll);
Nakor 0:7c89d9ec2d76 166
Nakor 1:2548417420a3 167 /** Send information about the current enemy.
Nakor 1:2548417420a3 168 *
Nakor 1:2548417420a3 169 * Pass amount of health and (optionally) level of current enemy.
Nakor 1:2548417420a3 170 *
Nakor 1:2548417420a3 171 * @param health Amount of enemy health left.
Nakor 1:2548417420a3 172 * @param level Enemy level (optional). Defaults to 0x00.
Nakor 1:2548417420a3 173 *
Nakor 1:2548417420a3 174 * Example:
Nakor 1:2548417420a3 175 * @code
Nakor 1:2548417420a3 176 * // Create a new player object.
Nakor 1:2548417420a3 177 * player *user = new player();
Nakor 1:2548417420a3 178 *
Nakor 1:2548417420a3 179 * int main()
Nakor 1:2548417420a3 180 * {
Nakor 1:2548417420a3 181 * // Get current enemy health
Nakor 1:2548417420a3 182 * int enemyHealth = currentEnemy->getHealth();
Nakor 1:2548417420a3 183 * // Send update on enemy health status to user
Nakor 1:2548417420a3 184 * user->setCurrentEnemy(enemyHealth);
Nakor 1:2548417420a3 185 * }
Nakor 1:2548417420a3 186 * @endcode
Nakor 1:2548417420a3 187 */
Nakor 0:7c89d9ec2d76 188 void setCurrentEnemy(int health, char level = 0x00);
Nakor 0:7c89d9ec2d76 189
Nakor 1:2548417420a3 190 /** Check to see if the player is dead.
Nakor 1:2548417420a3 191 *
Nakor 1:2548417420a3 192 * If player is dead it makes fun of player and pretends to restart everything.
Nakor 1:2548417420a3 193 * Returns true if player is dead.
Nakor 1:2548417420a3 194 *
Nakor 1:2548417420a3 195 * Example:
Nakor 1:2548417420a3 196 * @code
Nakor 1:2548417420a3 197 * // Create a new player object.
Nakor 1:2548417420a3 198 * player *user = new player();
Nakor 1:2548417420a3 199 *
Nakor 1:2548417420a3 200 * int main()
Nakor 1:2548417420a3 201 * {
Nakor 1:2548417420a3 202 * char thereIsCake = user->isDead();
Nakor 1:2548417420a3 203 * if(thereIsCake)
Nakor 1:2548417420a3 204 * {
Nakor 1:2548417420a3 205 * // Do your delete and new code here
Nakor 1:2548417420a3 206 * }
Nakor 1:2548417420a3 207 * }
Nakor 1:2548417420a3 208 * @endcode
Nakor 1:2548417420a3 209 */
Nakor 0:7c89d9ec2d76 210 char isDead();
Nakor 0:7c89d9ec2d76 211
Nakor 0:7c89d9ec2d76 212 protected:
Nakor 1:2548417420a3 213 /**
Nakor 1:2548417420a3 214 * Variable to hold amount of player's experience points.
Nakor 1:2548417420a3 215 */
Nakor 0:7c89d9ec2d76 216 unsigned long int _experience;
Nakor 0:7c89d9ec2d76 217
Nakor 1:2548417420a3 218 /**
Nakor 1:2548417420a3 219 * Variable to hold the current enemy's level.
Nakor 1:2548417420a3 220 */
Nakor 0:7c89d9ec2d76 221 char _enemyLevel;
Nakor 1:2548417420a3 222 /**
Nakor 1:2548417420a3 223 * Variable to hold the current enemy's health.
Nakor 1:2548417420a3 224 */
Nakor 0:7c89d9ec2d76 225 int _enemyHealth;
Nakor 0:7c89d9ec2d76 226
Nakor 1:2548417420a3 227 /**
Nakor 1:2548417420a3 228 * Base health of player (that is then multiplied by level).
Nakor 1:2548417420a3 229 */
Nakor 0:7c89d9ec2d76 230 int _baseHealth;
Nakor 0:7c89d9ec2d76 231 };
Nakor 0:7c89d9ec2d76 232
Nakor 0:7c89d9ec2d76 233 #endif