Class Creature

java.lang.Object
  extended by Creature

public class Creature
extends java.lang.Object

This class represents a Creature within our game. For full details of the Creature class, see HW J6.


Constructor Summary
Creature()
          Creates a default creature.
Creature(int hp, int str, int skl, int ac, java.lang.String name, java.lang.String type, java.lang.String pronoun)
          Creates a creature with the attributes set to the passed values.
 
Method Summary
 int calcHitDamage()
          Calculates how much damage the creature did on a successful attack.
 java.lang.String constructHitString(Creature other)
          Returns a String stating that the creature successfully hit the passed opponent.
 java.lang.String constructMissString(Creature other)
          Returns a String stating that the creature successfully missed the passed opponent.
 boolean getAngry()
          Returns whether the creature is angry or not
 int getArmorClass()
          Gets the creature's armor class
 int getHitPoints()
          Gets the creature's hit points
 java.lang.String getName()
          Gets the creature's name (i.e., 'Frodo')
 java.lang.String getPronoun()
          Gets the creature's pronoun (i.e., 'his', her', 'its', etc.)
 int getSkill()
          Gets the creature's skill level
 int getStrength()
          Gets the creature's strength
 java.lang.String getType()
          Gets the creature's type (i.e., 'hobbit')
 Weapon getWeapon()
          Gets the creature's weapon
 boolean isAlive()
          Returns whether the creature is still alive or not.
 void setAngry()
          Sets the creature to be angry.
 void setAngry(boolean toWhat)
          Sets the creature to be angry.
 void setArmorClass(int ac)
          Sets the creature's armor class
 void setHitPoints(int hp)
          Sets the creature's hit points
 void setName(java.lang.String nm)
          Sets the creature's name (i.e., 'Frodo')
 void setPronoun(java.lang.String pn)
          Sets the creature's pronoun (i.e., 'his', her', 'its', etc.)
 void setSkill(int skl)
          Sets the creature's skill
 void setStrength(int str)
          Sets the creature's strength
 void setType(java.lang.String tp)
          Sets the creature's type (i.e, 'hobbit')
 void setWeapon(Weapon w)
          Sets the creature's weapon
 void takeDamage(int damage)
          Causes the creature to take the passed amount of damage.
 boolean tryToAttack(int targetAC)
          Returns whether the creature successfully managed to attack a target with the passed armor class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Creature

public Creature()
Creates a default creature. The creature is set with the following attributes: hitPoints = 50, strength = 15, skill = 15, armorClass = 5, name = "Somebody", type = "nondescript creature", and pronoun = "its".


Creature

public Creature(int hp,
                int str,
                int skl,
                int ac,
                java.lang.String name,
                java.lang.String type,
                java.lang.String pronoun)
Creates a creature with the attributes set to the passed values.

Parameters:
hp - How many hit points this creature should have
str - The creature's strength
skl - The creature's skill level
ac - The creature's armor class
name - The creature's name (i.e., 'Frodo')
type - The creature's type (i.e., 'hobbit')
pronoun - The pronoun for the creature (i.e., 'his', her', 'its', etc.)
Method Detail

getAngry

public boolean getAngry()
Returns whether the creature is angry or not

Returns:
Whether the creature is angry or not

setAngry

public void setAngry()
Sets the creature to be angry. Note that creatures in this game should never be set to be not-angry.


setAngry

public void setAngry(boolean toWhat)
Sets the creature to be angry. Note that creatures in this game should never be set to be not-angry. However, this method is included for those who put in a parameter anyway.

Parameters:
toWhat - Whether the creature should be set to angry or not.

getHitPoints

public int getHitPoints()
Gets the creature's hit points

Returns:
The creature's hit points

getStrength

public int getStrength()
Gets the creature's strength

Returns:
The creature's strength

getSkill

public int getSkill()
Gets the creature's skill level

Returns:
The creature's skill level

getArmorClass

public int getArmorClass()
Gets the creature's armor class

Returns:
The creature's armor class

getName

public java.lang.String getName()
Gets the creature's name (i.e., 'Frodo')

Returns:
The creature's name

getType

public java.lang.String getType()
Gets the creature's type (i.e., 'hobbit')

Returns:
The creature's type

getPronoun

public java.lang.String getPronoun()
Gets the creature's pronoun (i.e., 'his', her', 'its', etc.)

Returns:
The creature's pronoun

getWeapon

public Weapon getWeapon()
Gets the creature's weapon

Returns:
The creature's weapon

setHitPoints

public void setHitPoints(int hp)
Sets the creature's hit points

Parameters:
hp - The creature's hit points

setStrength

public void setStrength(int str)
Sets the creature's strength

Parameters:
str - The creature's strength

setSkill

public void setSkill(int skl)
Sets the creature's skill

Parameters:
skl - The creature's skill

setArmorClass

public void setArmorClass(int ac)
Sets the creature's armor class

Parameters:
ac - The creature's armor class

setName

public void setName(java.lang.String nm)
Sets the creature's name (i.e., 'Frodo')

Parameters:
nm - The creature's name

setType

public void setType(java.lang.String tp)
Sets the creature's type (i.e, 'hobbit')

Parameters:
tp - The creature's name

setPronoun

public void setPronoun(java.lang.String pn)
Sets the creature's pronoun (i.e., 'his', her', 'its', etc.)

Parameters:
pn - The creature's pronoun

setWeapon

public void setWeapon(Weapon w)
Sets the creature's weapon

Parameters:
w - The creature's weapon

isAlive

public boolean isAlive()
Returns whether the creature is still alive or not. If the creature has zero or fewer hit points, then it is dead.

Returns:
Whether the creature is alive or not.

tryToAttack

public boolean tryToAttack(int targetAC)
Returns whether the creature successfully managed to attack a target with the passed armor class. This uses a random number based on the creature's skill to see if the attack was successful.

Parameters:
targetAC - The target armor class of the creature's opponent
Returns:
Whether the creature attacked a target with the passed armor class

calcHitDamage

public int calcHitDamage()
Calculates how much damage the creature did on a successful attack. This uses the creature's weapon's damage modifier (via Weapon.getDamageModifier() and a random number based on the creature's strength.

Returns:
How much damage the creature did on a successful attack.

takeDamage

public void takeDamage(int damage)
Causes the creature to take the passed amount of damage. This method also prints out how many hit points the creature has left.

Parameters:
damage - How much damage this creature took.

constructHitString

public java.lang.String constructHitString(Creature other)
Returns a String stating that the creature successfully hit the passed opponent. The string is of the form " the the with ".

Parameters:
other - The creature's opponent. This is needed for part of the returned hit string.
Returns:
A String stating that the creature successfully hit the passed opponent.

constructMissString

public java.lang.String constructMissString(Creature other)
Returns a String stating that the creature successfully missed the passed opponent. The string is of the form " the the with ".

Parameters:
other - The creature's opponent. This is needed for part of the returned miss string.
Returns:
A String stating that the creature successfully missed the passed opponent.