package main; import java.util.LinkedList; import gamegui.Animation; public class Turret extends Unit { int damage; Unit target; Animation projectileImg; public Turret(final String name, final Animation img, final int damage, final int hitpoints, final int fireRate, final Animation projectileImg) { super(name, img, hitpoints); this.damage = damage; this.projectileImg = projectileImg; this.actions.add(new Action.Fire(fireRate)); } public int getDamage() { return this.damage; } @Override public void perform(final Action action, final LinkedList lstObjects, final LinkedList lstTargets) { if (action instanceof Action.Fire) { this.perform((Action.Fire)action, lstObjects, lstTargets); } } public void perform(final Action.Fire action, final LinkedList lstObjects, final LinkedList lstTargets) { if (lstTargets.size() == 0) { this.target = null; return; } if (this.target == null || this.target.remove) { this.target = lstTargets.get((int)(Math.random() * lstTargets.size())); } lstObjects.add(this.fire(this.target)); } public Projectile fire(final Unit target) { final Projectile proj = new Projectile("Projectile", this.projectileImg, 400, target.loc, target, this.damage); proj.setLocation(this.loc); return proj; } }