Package characters
Class DungeonCharacter
java.lang.Object
characters.DungeonCharacter
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
public abstract class DungeonCharacter
extends java.lang.Object
implements java.lang.Comparable<java.lang.Object>
Abstract Base class for inheritance hierarchy for a role playing game.
-
Field Summary
Fields Modifier and Type Field Description protected int
attackSpeed
protected double
chanceToHit
protected int
damageMax
protected int
damageMin
protected int
hitPoints
protected java.lang.String
name
protected java.util.Random
randomInt
-
Constructor Summary
Constructors Modifier Constructor Description protected
DungeonCharacter(java.lang.String name, int hitPoints, int attackSpeed, double chanceToHit, int damageMin, int damageMax)
Explicit constructor to initialize instance variables. -
Method Summary
Modifier and Type Method Description void
addHitPoints(int hitPoints)
Increments the hitPoints that a dungeon character has.void
attack(DungeonCharacter opponent)
Allows characters to attempt an attack on an opponent.abstract void
battleChoices(DungeonCharacter opponent)
Abstract of the battleChoices class, to be implemented by the Hero class.int
compareTo(java.lang.Object o)
int
getAttackSpeed()
Return the character's attack speed.int
getHitPoints()
Return a character's hit points (health).java.lang.String
getName()
Return the character's name.boolean
isAlive()
Used to see if a character is still alive by checking their hit points.void
subtractHitPoints(int hitPoints)
Decrements the hitPoints a dungeon character has.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
name
protected java.lang.String name -
hitPoints
protected int hitPoints -
attackSpeed
protected int attackSpeed -
chanceToHit
protected double chanceToHit -
damageMin
protected int damageMin -
damageMax
protected int damageMax -
randomInt
protected java.util.Random randomInt
-
-
Constructor Details
-
DungeonCharacter
protected DungeonCharacter(java.lang.String name, int hitPoints, int attackSpeed, double chanceToHit, int damageMin, int damageMax)Explicit constructor to initialize instance variables.- Parameters:
name
- Name of character.hitPoints
- Points of damage a character can take before killed.attackSpeed
- How fast the character can attack.chanceToHit
- Chance an attack will strike the opponent.damageMin
- Minimum amount of damage a character can inflict.damageMax
- Maximum amount of damage a character can inflict.
-
-
Method Details
-
compareTo
public int compareTo(java.lang.Object o)- Specified by:
compareTo
in interfacejava.lang.Comparable<java.lang.Object>
-
getName
public java.lang.String getName()Return the character's name. -
getHitPoints
public int getHitPoints()Return a character's hit points (health). -
getAttackSpeed
public int getAttackSpeed()Return the character's attack speed. -
addHitPoints
public void addHitPoints(int hitPoints)Increments the hitPoints that a dungeon character has.- Parameters:
hitPoints
- The number of hit points to add.
-
subtractHitPoints
public void subtractHitPoints(int hitPoints)Decrements the hitPoints a dungeon character has. TODO: It also reports the damage and remaining hit points (these things could be done in separate methods to make code more modular ;-)- Parameters:
hitPoints
- The number of hit points to subtract.
-
isAlive
public boolean isAlive()Used to see if a character is still alive by checking their hit points.- Returns:
- True if hero is alive, false otherwise.
-
attack
Allows characters to attempt an attack on an opponent. First, chance to hit is considered. If a hit can occur, then the damage is calculated based on character's damage range. This damage is then applied to the opponent.- Parameters:
opponent
- The opponent being attacked.
-
battleChoices
Abstract of the battleChoices class, to be implemented by the Hero class.- Parameters:
opponent
- The opponent to be fought.
-