javoids
Class Health

java.lang.Object
  extended by javoids.Health
All Implemented Interfaces:
java.io.Serializable

public class Health
extends java.lang.Object
implements java.io.Serializable

Health.java is used to keep track of a sprite's duration and damage level.

See Also:
Serialized Form

Nested Class Summary
static class Health.DurationType
          sprite's duration/immortality type
 
Field Summary
private  int agingRate
          the amount that the sprite ages after each delay
private  int damage
          the sprite's damage level
private  int deaths
          the number of deaths the sprite has
static int DEFAULT_AGING_RATE
          standard rate that sprites decay (take it off duration of sprite after every delay)
static int DEFAULT_DAMAGE_CAPACITY
          standard damage capacity for a sprite
static int DEFAULT_DEATHS
          standard number of deaths for a sprite
static int DEFAULT_DURATION
          standard amount of "ticks" that a sprite can survive for (if not ageless and an aging rate of -1)
private  int duration
          the sprite's duration time
static int MAX_DEATHS
          standard maximum number of deaths for any sprite (>= minimum number of deaths and <= 9)
private  int maxDamage
          the sprite's maximum damage level
private  int maxDeaths
          the maxmimum number of deaths the sprite has
private  int maxDuration
          the sprite's maximum duration
static int MIN_DEATHS
          standard minimum number of deaths a sprite can have (>= 1 always)
private static long serialVersionUID
          This is the version used for serializing/deserializing (storing/retrieving) this object
private  Health.DurationType state
          the state of the sprite's duration type
 
Constructor Summary
Health()
          default constructor
Health(Health health)
          copy constructor
Health(int _maxLives, int _maxDamage, int _maxDuration, int _agingRate, Health.DurationType _state)
          constructor that accepts parameters for every value
 
Method Summary
 void age()
          Cause the object to age (reduces duration if it is not ageless)
 int getAgingRate()
          return the aging rate of the sprite
 int getDamage()
          return the hit points of the sprite
 int getDeaths()
          return the number of deaths of the sprite
 int getDuration()
          return the duration left for the sprite
 int getMaxDamage()
          return the maximum hit points of the sprite
 int getMaxDeaths()
          return the maximum number of deaths of the sprite
 int getMaxDuration()
          return the maximum duration left for the sprite
 boolean isAgeless()
          Is the object ageless (won't die from aging, but will from damage)?
 boolean isAlive()
          Is the object alive?
 boolean isImmortal()
          Is the object immortal (won't die from damage or aging)?
 boolean isRestorable()
           
 int modifyDamage(int _damage)
          Modify the number of hitpoints for an object if it is not immortal.
 int modifyDeaths(int _deaths)
          Modify the number of deaths for an object if it is not immortal.
 int modifyDuration(int _duration)
          Modify the amount of duration for an object if it is not ageless.
 void setAgingRate(int _agingRate)
          Set the rate that the object decays (time it has left) before it is destroyed.
 void setDamage(int _damage)
          Set the number of hitpoints for an object (the amount of damage it can take before a lfie is taken ).
 void setDeaths(int _deaths)
          Set the number of deaths for an object (the number of times it may die).
 void setDuration(int _duration)
          Set the amount of time that an object will survive.
 void setMaxDamage(int _maxDamage)
          Set the maximum number of hitpoints an object may have (but doesn't necessarily have).
 void setMaxDeaths(int _maxLives)
          Set the maximum number of deaths an object may have (but doesn't necessarily have).
 void setMaxDuration(int _maxDuration)
          Set the maximum amount of tie the object will survive.
 void setState(Health.DurationType _state)
          Set the state the object is in (NORMAL,AGELESS,IMMORTAL,IMMORTAL_AGELESS).
 java.lang.String toString()
          Provide a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
This is the version used for serializing/deserializing (storing/retrieving) this object

See Also:
Constant Field Values

DEFAULT_AGING_RATE

public static int DEFAULT_AGING_RATE
standard rate that sprites decay (take it off duration of sprite after every delay)


DEFAULT_DAMAGE_CAPACITY

public static int DEFAULT_DAMAGE_CAPACITY
standard damage capacity for a sprite


DEFAULT_DURATION

public static int DEFAULT_DURATION
standard amount of "ticks" that a sprite can survive for (if not ageless and an aging rate of -1)


DEFAULT_DEATHS

public static int DEFAULT_DEATHS
standard number of deaths for a sprite


MAX_DEATHS

public static int MAX_DEATHS
standard maximum number of deaths for any sprite (>= minimum number of deaths and <= 9)


MIN_DEATHS

public static int MIN_DEATHS
standard minimum number of deaths a sprite can have (>= 1 always)


agingRate

private int agingRate
the amount that the sprite ages after each delay


damage

private int damage
the sprite's damage level


duration

private int duration
the sprite's duration time


deaths

private int deaths
the number of deaths the sprite has


maxDamage

private int maxDamage
the sprite's maximum damage level


maxDuration

private int maxDuration
the sprite's maximum duration


maxDeaths

private int maxDeaths
the maxmimum number of deaths the sprite has


state

private Health.DurationType state
the state of the sprite's duration type

Constructor Detail

Health

public Health()
default constructor


Health

public Health(Health health)
copy constructor

Parameters:
health - the Health object to copy

Health

public Health(int _maxLives,
              int _maxDamage,
              int _maxDuration,
              int _agingRate,
              Health.DurationType _state)
constructor that accepts parameters for every value

Parameters:
_maxLives - the maximum number of deaths
_maxDamage - the maximum damage capactiy of the sprite
_maxDuration - the maximum number of time units "ticks" the object will survive
_agingRate - the rate that the sprite decays (the number of "ticks" used up after every delay)
_state - the state of the object (normal, ageless, immortal, etc)
Method Detail

age

public void age()
Cause the object to age (reduces duration if it is not ageless)


getAgingRate

public int getAgingRate()
return the aging rate of the sprite

Returns:
this.agingRate

getDamage

public int getDamage()
return the hit points of the sprite

Returns:
the current damage level

getDuration

public int getDuration()
return the duration left for the sprite

Returns:
duration

getDeaths

public int getDeaths()
return the number of deaths of the sprite

Returns:
this.lives

getMaxDamage

public int getMaxDamage()
return the maximum hit points of the sprite

Returns:
the maximum damage level allowable before the object dies

getMaxDuration

public int getMaxDuration()
return the maximum duration left for the sprite

Returns:
this.maxDuration

getMaxDeaths

public int getMaxDeaths()
return the maximum number of deaths of the sprite

Returns:
this.maxLives

isAgeless

public boolean isAgeless()
Is the object ageless (won't die from aging, but will from damage)?

Returns:
true/false

isAlive

public boolean isAlive()
Is the object alive?

Returns:
true/false

isImmortal

public boolean isImmortal()
Is the object immortal (won't die from damage or aging)?

Returns:
true/false

isRestorable

public boolean isRestorable()
Returns:
whether or not the object can be restored (i.e. it has lives left)

modifyDamage

public int modifyDamage(int _damage)
Modify the number of hitpoints for an object if it is not immortal.

Parameters:
_damage - the number of hitpoints to give an object (positive values grants hitpoints, negative values take hitpoints away).
Returns:
The current number of hitpoints an object has.

modifyDuration

public int modifyDuration(int _duration)
Modify the amount of duration for an object if it is not ageless.

Parameters:
_duration - the amount of duration to give an object (positive values grants duration, negative values take duration away).
Returns:
The current amount of duration an object has.

modifyDeaths

public int modifyDeaths(int _deaths)
Modify the number of deaths for an object if it is not immortal.

Parameters:
_deaths - the number of deaths to give an object (positive values grants deaths, negative values take deaths away).
Returns:
The current number of deaths an object has.

setAgingRate

public void setAgingRate(int _agingRate)
Set the rate that the object decays (time it has left) before it is destroyed.

Parameters:
_agingRate - The rate that the object decays (time it has left) before it is destroyed.

setDamage

public void setDamage(int _damage)
Set the number of hitpoints for an object (the amount of damage it can take before a lfie is taken ).

Parameters:
_damage - The number of hitpointslives the object will have (0 <= __damage <= maxDamage)

setDuration

public void setDuration(int _duration)
Set the amount of time that an object will survive.

Parameters:
_duration - The amount of time the object will survive the object will have (0 <= _duration <= maxDuration)

setDeaths

public void setDeaths(int _deaths)
Set the number of deaths for an object (the number of times it may die).

Parameters:
_deaths - The number of deaths the object will have (0 <= _lives <= MAX_DEATHS)

setMaxDamage

public void setMaxDamage(int _maxDamage)
Set the maximum number of hitpoints an object may have (but doesn't necessarily have).

Parameters:
_maxDamage - The maximum number of hitpoints the object will have (_maxDamage >= 1)

setMaxDuration

public void setMaxDuration(int _maxDuration)
Set the maximum amount of tie the object will survive.

Parameters:
_maxDuration - The maximum amount of time the object will survive (_maxDuration >= 1)

setMaxDeaths

public void setMaxDeaths(int _maxLives)
Set the maximum number of deaths an object may have (but doesn't necessarily have).

Parameters:
_maxLives - The maximum number of deaths the object will have (_maxLives >= MIN_DEATHS)

setState

public void setState(Health.DurationType _state)
Set the state the object is in (NORMAL,AGELESS,IMMORTAL,IMMORTAL_AGELESS).

Parameters:
_state - The state the object is in.

toString

public java.lang.String toString()
Provide a String representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
String A representation of the object for debugging.