Aaron Goselin / player

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

Embed: (wiki syntax)

« Back to documentation index

player Class Reference

Player class derived from life_entity. More...

#include <player.h>

Public Member Functions

 player ()
 Player class constructor.
unsigned long int getExperience ()
 Get the number of experience points the player currently has.
char getLevel ()
 Get the number player's current level.
void isLevelUp ()
 Check to see if the player is ready to level up.
void addExperience ()
 Add experience points (and apply rest health).
void displayExpRamp ()
 Display player experience ramp.
virtual void takeDamage (int roll)
 Take damage from apponent.
void setCurrentEnemy (int health, char level=0x00)
 Send information about the current enemy.
char isDead ()
 Check to see if the player is dead.

Protected Attributes

unsigned long int _experience
 Variable to hold amount of player's experience points.
char _enemyLevel
 Variable to hold the current enemy's level.
int _enemyHealth
 Variable to hold the current enemy's health.
int _baseHealth
 Base health of player (that is then multiplied by level).

Detailed Description

Player class derived from life_entity.

This class is derived from life_entity.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Get the user's level (for example)
     char playerLevel = user->getLevel();
 }

Definition at line 27 of file player.h.


Constructor & Destructor Documentation

player (  )

Player class constructor.

This class is derived from life_entity.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Get the user's level (for example)
     char playerLevel = user->getLevel();
 }

Definition at line 21 of file player.cpp.


Member Function Documentation

void addExperience (  )

Add experience points (and apply rest health).

Add experience points for the win and calculate bonus health from 'rest'.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Add experience points to player
     user->addExperience();
 }

Definition at line 77 of file player.cpp.

void displayExpRamp (  )

Display player experience ramp.

Display the amount of experience required for each level.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Print experience ramp
     user->displayExpRamp();
 }

Definition at line 111 of file player.cpp.

unsigned long int getExperience (  )

Get the number of experience points the player currently has.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Get the user's xp
     unsigned long int xp = user->getExperience();
 }

Definition at line 39 of file player.cpp.

char getLevel (  )

Get the number player's current level.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Get the user's level
     char playerLevel = user->getLevel();
 }

Definition at line 153 of file player.cpp.

char isDead (  )

Check to see if the player is dead.

If player is dead it makes fun of player and pretends to restart everything. Returns true if player is dead.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
       char thereIsCake = user->isDead();
       if(thereIsCake)
       {
           // Do your delete and new code here
       }
 }

Definition at line 172 of file player.cpp.

void isLevelUp (  )

Check to see if the player is ready to level up.

Compare the player's current experience with the amount of experience required to reach the next level. If enough experience is present, level up the player.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
     // Check for level up
     user->isLevelUp();
 }

Definition at line 46 of file player.cpp.

void setCurrentEnemy ( int  health,
char  level = 0x00 
)

Send information about the current enemy.

Pass amount of health and (optionally) level of current enemy.

Parameters:
healthAmount of enemy health left.
levelEnemy level (optional). Defaults to 0x00.

Example:

 // Create a new player object.
 player *user = new player();

 int main()
 {    
       // Get current enemy health
       int enemyHealth = currentEnemy->getHealth();
       // Send update on enemy health status to user
       user->setCurrentEnemy(enemyHealth);
 }

Definition at line 160 of file player.cpp.

void takeDamage ( int  roll ) [virtual]

Take damage from apponent.

This applies the enemy's damage roll to the player's health after a dodge roll is performed.

Parameters:
rollThe damage roll to be passed in (most likely from rollDamage()).

Example:

 player *user = new player();
 life_entity *currentEnemy; 

 int main()
 {    
     // Use the pointer to create a new armoured_vehicle (derived class)
     currentEnemy = new enemy(user);
     
     // Enemy rolls for damage
     int roll = currentEnemy->rollDamage();
     // Player takes the hit
     user->takeDamage(roll);
 }

Definition at line 133 of file player.cpp.


Field Documentation

int _baseHealth [protected]

Base health of player (that is then multiplied by level).

Definition at line 230 of file player.h.

int _enemyHealth [protected]

Variable to hold the current enemy's health.

Definition at line 225 of file player.h.

char _enemyLevel [protected]

Variable to hold the current enemy's level.

Definition at line 221 of file player.h.

unsigned long int _experience [protected]

Variable to hold amount of player's experience points.

Definition at line 216 of file player.h.