Life entity (base class). Written for OOP Review.
Dependencies: armoured_vehicle enemy player
Revision 0:cee9139ed454, committed 2011-03-31
- Comitter:
- Nakor
- Date:
- Thu Mar 31 19:56:40 2011 +0000
- Child:
- 1:0b3582b2b45f
- Commit message:
- Documentation complete (I think).
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/armoured_vehicle.lib Thu Mar 31 19:56:40 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Nakor/code/armoured_vehicle/#915b6c03bd04
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enemy.lib Thu Mar 31 19:56:40 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Nakor/code/enemy/#91a68e5fd4b8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/life_entity.cpp Thu Mar 31 19:56:40 2011 +0000 @@ -0,0 +1,72 @@ +#include "life_entity.h" + +int life_entity::lifeEntityCount = 0; + +// Constructor +// Sets up basic variables and adds to entity counter +life_entity::life_entity() +{ + _level = 0x01; + + _health = _level * 100; + + lifeEntityCount++; +} + +// Destructor (virtual) +// Simply modifies the entity counter +life_entity::~life_entity() +{ + lifeEntityCount--; +} + + +// Return life entity count +char life_entity::getLifeEntityCount() +{ + return lifeEntityCount; +} + +// Returns the current health of the entity +int life_entity::getHealth() +{ + return _health; +} + +// Returns the level of the entity +char life_entity::getLevel() +{ + return _level; +} + +// Roll for damage +// This is currently the same for all entities. +// Different damage is currently applied in main (like one third damage that user takes) +int life_entity::rollDamage() +{ + int maxDmg = 7; + srand ( time(NULL) ); + + int roll = (rand() % (maxDmg * _level) + 1); + + srand ( time(NULL) ); + + int isCrit = ( rand() % 1000 + 1); + + if(isCrit >= 800) + { + isCrit = 1; + } + else + { + isCrit = 0; + } + + if(isCrit) + { + printf("CRIT!\n"); + roll = (maxDmg * 2) - ( rand() % 4 + 1 ); + } + + return roll; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/life_entity.h Thu Mar 31 19:56:40 2011 +0000 @@ -0,0 +1,149 @@ +#ifndef _LIFEENTITY_ +#define _LIFEENTITY_ + +#include "mbed.h" + +/** Base life entity class. + * + * This class is inherited by all life entities (user, enemies, anything you can think of that + * is supposed to live). + * + * Example: + * @code + * // Create a pointer to a life_entity object. + * #include "mbed.h" + * #include "uOLED.h" + * + * life_entity *currentEnemy; + * + * int main() + * { + * // Use the pointer to create a new armoured_vehicle (derived class) + * currentEnemy = new armoured_vehicle(user); + * } + * @endcode + */ +class life_entity +{ + +public: + /** Base life entity class constructor. + * + * This class is inherited by all life entities (user, enemies, anything you can think of that + * is supposed to live). + * + * Example: + * @code + * // Create a pointer to a life_entity object. + * #include "mbed.h" + * #include "uOLED.h" + * + * life_entity *currentEnemy; // Life entity object + * + * int main() + * { + * // Use the pointer to create a new armoured_vehicle (derived class) + * currentEnemy = new armoured_vehicle(user); + * } + * @endcode + */ + life_entity(); + + /** Base life entity class destructor. + * + * This class is inherited by all life entities (user, enemies, anything you can think of that + * is supposed to live). + * + * Example: + * @code + * // Create a pointer to a life_entity object. + * #include "mbed.h" + * #include "uOLED.h" + * + * life_entity *currentEnemy; + * + * int main() + * { + * // Use the pointer to create a new armoured_vehicle (derived class) + * currentEnemy = new armoured_vehicle(user); + * + * delete currentEnemy; + * } + * @endcode + */ + virtual ~life_entity(); + + /** Get number of life entities currently spawned. + * + * + * Example: + * @code + * char count = getLifeEntityCount(); + * @endcode + */ + char getLifeEntityCount(); + + /** Returns the current status of the entity's life points. + * + * + * Example: + * @code + * int lifePoints = getHealth(); + * @endcode + */ + int getHealth(); + + /** Get the current level of the entity. + * + * No error checking is performed. If you wish to use this you + * should consider adding a check or two. + * The level is currently stored in a char, and therefore maxes + * out at 255 (0xFF). + * + * Example: + * @code + * char currentLevel = getLevel(); + * @endcode + */ + char getLevel(); + + /** Entity rolls for damage. + * + * All entities use this to roll for damage (against thier opponent). + * + * Example: + * @code + * int roll = rollDamage(); + * @endcode + */ + int rollDamage(); + + /** Take damage from apponent. + * + * Derived classes set this up on specific to thier needs. + * + * @param roll The damage roll to be passed in (most likely from rollDamage()). + * + */ + virtual void takeDamage(int) { }; + + +protected: + /** + * Entity health variable (int). + */ + int _health; + + /** + * Entity level variable (char). + */ + char _level; + + /** + * Static entity count variable (int). + */ + static int lifeEntityCount; + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/player.lib Thu Mar 31 19:56:40 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Nakor/code/player/#7c89d9ec2d76