Package model
Class Tower
java.lang.Object
model.Tower
public class Tower
extends java.lang.Object
A tower attacks troops within its specified range with its specified attack interval and damage output.
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.image.BufferedImage
towerImage
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
attack(Troop troop)
attack() - Tries to attack a given troop if the troop is in range.Position
getPosition()
getPosition()java.awt.image.BufferedImage
getTowerImage()
getTowerImage()boolean
inRange(Position troopPos)
inRange() - Calculates the distance to a troop and checks if it is range of the tower.
-
Field Details
-
towerImage
protected java.awt.image.BufferedImage towerImage
-
-
Constructor Details
-
Tower
public Tower(java.lang.Integer attackInterval, java.lang.Integer damageOutput, Position position, java.lang.Integer radius, java.awt.image.BufferedImage towerImage)Tower constructor- Parameters:
attackInterval
- - Time in milliseconds between attacks.damageOutput
- - Damage dealt.position
- - Position of tower.radius
- - Radius of how far away the tower can shoot at troops.towerImage
- - Image representing tower.
-
-
Method Details
-
attack
attack() - Tries to attack a given troop if the troop is in range. If the troop is in range. Damage equivalent to damageOutput is subtracted from the troops health pool.- Parameters:
troop
- The troop to try attacking.- Returns:
- True if the troop is in range for attack. False otherwise.
-
inRange
inRange() - Calculates the distance to a troop and checks if it is range of the tower.- Parameters:
troopPos
- Position of a troop to check.- Returns:
- True if the troop is in range. False otherwise.
-
getTowerImage
public java.awt.image.BufferedImage getTowerImage()getTowerImage()- Returns:
- - Image that represents towers in user interface.
-
getPosition
getPosition()- Returns:
- - Position of tower.
-