package main; import java.util.Iterator; import java.util.LinkedList; import gamegui.Animation; public class Shield extends Unit { int radius; public Shield(final String name, final Animation img, final int hitpoints, final int radius) { super(name, img, hitpoints); this.radius = radius; this.actions.add(new Action.Defend(5L)); } @Override public void perform(final Action action, final LinkedList lstObjects, final LinkedList lstTargets) { if (action instanceof Action.Defend) { this.perform((Action.Defend)action, lstObjects, lstTargets); } } public void perform(final Action.Defend action, final LinkedList lstObjects, final LinkedList lstTargets) { for (final Entity cur : lstObjects) { if (cur instanceof Projectile && !(((Projectile)cur).getTarget() instanceof Ship) && this.loc.distance(cur.loc) <= this.radius && !((Projectile)cur).exploded) { ((Projectile)cur).exploded = true; ((Projectile)cur).timeExploded = System.currentTimeMillis(); this.takeDamage(((Projectile)cur).getDamage()); if (this.getHitpoints() != 0) { continue; } this.remove = true; } } } }