diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 9ccf998..fbb197d 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -7,6 +7,7 @@ import worms.util.IllegalNameException; import static java.lang.Math.*; +import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -1217,6 +1218,16 @@ public class Worm extends GameObject { //TODO location overlaps with 1 or more projectiles => firing worm is hit by one overlapping projectile //TODO => method returns null + if (! getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) { + List projectiles = getWorld().getGameObjectsByClass(Projectile.class); + for (Projectile project: projectiles) { + if (this.getDistance(project) <= 0) { + project.hit(this); + return null; + } + } + } + int random = ThreadLocalRandom.current().nextInt(2);