Class RangedUnit
java.lang.Object
edu.ntnu.idatt2001.carljgu.battle.units.Unit
edu.ntnu.idatt2001.carljgu.battle.units.specialized.RangedUnit
Class RangedUnit that inherits from Unit.
RangedUnit 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 final int
private int
-
Constructor Summary
ConstructorDescriptionRangedUnit
(String name, int health) Instantiates a new Ranged unit with a simplified constructor.RangedUnit
(String name, int health, int attack, int armor) Instantiates a new Ranged unit. -
Method Summary
Modifier and TypeMethodDescriptionint
getAttackBonus
(Terrain terrain) Overrides the abstract method getAttackBonus from Unit.int
getResistBonus
(Terrain terrain) Overrides the abstract method getAttackBonus from Unit.
-
Field Details
-
ATTACK_BONUS
private final int ATTACK_BONUS- See Also:
-
INITIAL_RESIST_BONUS
private final int INITIAL_RESIST_BONUS- See Also:
-
FINAL_RESIST_BONUS
private final int FINAL_RESIST_BONUS- See Also:
-
HILL_BONUS
private final int HILL_BONUS- See Also:
-
FOREST_PENALTY
private final int FOREST_PENALTY- See Also:
-
timesResisted
private int timesResisted
-
-
Constructor Details
-
RangedUnit
Instantiates a new Ranged 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.
-
RangedUnit
Instantiates a new Ranged unit with a simplified constructor. Attack is set to 15 and health is set to 8 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 attack bonus is decreased if the terrain is forest and increased if the terrain is hills.- 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 getAttackBonus from Unit. The first time it is run, times resisted is less than 2 and therefore returns the initial resist bonus. The second time resisted is still less than 2, but the initial resist bonus is subtracted by 2. (initialResistBonus - 2 * timesResisted (1)). The third time and all other times this method is, the default finalResistBonus is used.- 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.
-