Package characters.heroes
Class Hero
java.lang.Object
characters.DungeonCharacter
characters.heroes.Hero
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
public abstract class Hero extends DungeonCharacter
Abstract base class for a hierarchy of heroes. It is derived from DungeonCharacter.
A Hero has battle choices: regular attack and a special skill which is defined by the
classes derived from Hero.
-
Field Summary
Fields Modifier and Type Field Description protected double
chanceToBlock
protected int
numTurns
Fields inherited from class characters.DungeonCharacter
attackSpeed, chanceToHit, damageMax, damageMin, hitPoints, name, randomInt
-
Constructor Summary
Constructors Modifier Constructor Description protected
Hero(java.lang.String name, int hitPoints, int attackSpeed, double chanceToHit, int damageMin, int damageMax, double chanceToBlock)
Call the base constructor and get the name of hero from the user. -
Method Summary
Modifier and Type Method Description void
numOfTurns(DungeonCharacter opponent)
void
readName()
Obtains the name for the hero specified by the user.void
subtractHitPoints(int hitPoints)
Check if the hero blocked the attack, and if so a message is displayed, otherwise the base version of this method is invoked to perform the subtraction operation.Methods inherited from class characters.DungeonCharacter
addHitPoints, attack, battleChoices, compareTo, getAttackSpeed, getHitPoints, getName, isAlive
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
chanceToBlock
protected double chanceToBlock -
numTurns
protected int numTurns
-
-
Constructor Details
-
Hero
protected Hero(java.lang.String name, int hitPoints, int attackSpeed, double chanceToHit, int damageMin, int damageMax, double chanceToBlock)Call the base constructor and get the name of hero from the user.- 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.chanceToBlock
- The chance to block an opponents attack.
-
-
Method Details
-
readName
public void readName()Obtains the name for the hero specified by the user. -
subtractHitPoints
public void subtractHitPoints(int hitPoints)Check if the hero blocked the attack, and if so a message is displayed, otherwise the base version of this method is invoked to perform the subtraction operation.- Overrides:
subtractHitPoints
in classDungeonCharacter
- Parameters:
hitPoints
- The number of hit points to subtract.
-
numOfTurns
-