Class CavalryUnit
java.lang.Object
edu.ntnu.idatt2001.carljgu.battle.units.Unit
edu.ntnu.idatt2001.carljgu.battle.units.specialized.CavalryUnit
- Direct Known Subclasses:
CommanderUnit
Class CavalryUnit that inherits from Unit.
CavalryUnit objects implements methods from
the superclass.
- Version:
- 1.4 01.05.2022
- Author:
- Carl Gützkow
-
Field Summary
Modifier and TypeFieldDescriptionprivate final int
private final int
private final int
private final int
private int
-
Constructor Summary
ConstructorDescriptionCavalryUnit
(String name, int health) Instantiates a new Cavalry unit with a simplified constructor.CavalryUnit
(String name, int health, int attack, int armor) Instantiates a new Cavalry unit. -
Method Summary
Modifier and TypeMethodDescriptionint
getAttackBonus
(Terrain terrain) Overrides the abstract method getAttackBonus from Unit.int
getResistBonus
(Terrain terrain) Overrides the abstract method getResistBonus from Unit.
-
Field Details
-
usedAttackBonus
private int usedAttackBonus -
MELEE_ATTACK_BONUS
private final int MELEE_ATTACK_BONUS- See Also:
-
RESIST_BONUS
private final int RESIST_BONUS- See Also:
-
PLAINS_BONUS
private final int PLAINS_BONUS- See Also:
-
FOREST_BONUS
private final int FOREST_BONUS- See Also:
-
-
Constructor Details
-
CavalryUnit
Instantiates a new Cavalry unit. Uses the constructor of its superclass Unit.- Parameters:
name
- String - a short name of the unit that can't be left with whitespace or empty.health
- int - HP - amount of health unit has. If it hits zero or more, the unit is dead.attack
- int - damage done, excluding attack bonus, on an enemy unit.armor
- int - damage resisted, excluding resist bonus, from an enemy unit.
-
CavalryUnit
Instantiates a new Cavalry unit with a simplified constructor. Attack is set to 20 and health is set to 12 Uses the constructor over since it instantiates other variables- Parameters:
name
- String - a short name of the unit that can't be left with whitespace or empty.health
- int - HP - amount of health unit has. If it hits zero or more, the unit is dead.
-
-
Method Details
-
getAttackBonus
Overrides the abstract method getAttackBonus from Unit. The first time it is run, the default usedAttackBonus is used to simulate the first charge. After that the attack bonus for melee is used instead throughout the CavalryUnit's lifetime. The bonus is also increased if the terrain is plains.- Specified by:
getAttackBonus
in classUnit
- Parameters:
terrain
- Terrain - the terrain where the attack occurs.- Returns:
- attackBonus - int - value of the attack bonus used when calculating an enemy unit's health in an attack.
-
getResistBonus
Overrides the abstract method getResistBonus from Unit. The resist bonus is increased if the terrain is forest.- Specified by:
getResistBonus
in classUnit
- Parameters:
terrain
- Terrain - the terrain where the attack occurs.- Returns:
- resistBonus - int - value of the resist bonus used when calculating this object's health in an attack.
-