From 20bc7330f62378385858843456b2d26224068884 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Tue, 22 May 2018 15:39:22 +0200 Subject: [PATCH] fixes --- OGP1718-Worms/src/worms/model/Bazooka.java | 2 +- OGP1718-Worms/src/worms/model/Program.java | 2 +- OGP1718-Worms/src/worms/model/Projectile.java | 6 +++--- OGP1718-Worms/src/worms/model/Worm.java | 19 ++++++++++--------- .../worms/model/Part3_FullFacadeTest.java | 3 +++ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Bazooka.java b/OGP1718-Worms/src/worms/model/Bazooka.java index 6b96891..b697e4b 100644 --- a/OGP1718-Worms/src/worms/model/Bazooka.java +++ b/OGP1718-Worms/src/worms/model/Bazooka.java @@ -30,7 +30,7 @@ public class Bazooka extends Projectile { } public static double calcForce(double actionPoints) { - double hp = 2.5 + actionPoints / 8.0; + double hp = 2.5 + (actionPoints - 25) % 8.0; if (hp > 9.5) return 9.5; return hp; } diff --git a/OGP1718-Worms/src/worms/model/Program.java b/OGP1718-Worms/src/worms/model/Program.java index 215b166..8bc9169 100644 --- a/OGP1718-Worms/src/worms/model/Program.java +++ b/OGP1718-Worms/src/worms/model/Program.java @@ -123,7 +123,7 @@ public class Program { case MOVE: try { actionHandler.move(worm); - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException | IllegalStateException e) { enoughAP = false; callStack.push(new CallStackNode(null, s)); return; diff --git a/OGP1718-Worms/src/worms/model/Projectile.java b/OGP1718-Worms/src/worms/model/Projectile.java index c376960..cd7876f 100644 --- a/OGP1718-Worms/src/worms/model/Projectile.java +++ b/OGP1718-Worms/src/worms/model/Projectile.java @@ -69,17 +69,17 @@ public abstract class Projectile extends GameObject { public static final double FORCE_TIME = 0.5; public Coordinate getJumpStep(double elapsedTime) { - if (Double.isNaN(elapsedTime) || elapsedTime > this.getJumpTime(elapsedTime) || elapsedTime < 0) + if (Double.isNaN(elapsedTime) || elapsedTime < 0) throw new IllegalArgumentException(); double velocity = this.jumpVelocity(); return Coordinate.create(getLocation().getX() + velocity * cos(getOrientation()) * elapsedTime, - getLocation().getY() + velocity * sin(getOrientation()) * elapsedTime - 0.5 * G * pow(elapsedTime, 2) ); + getLocation().getY() + velocity * sin(getOrientation()) * elapsedTime - 0.5 * G * pow(elapsedTime, 2)); } private double jumpVelocity() { - return getForce()/getMass() * FORCE_TIME; + return getForce() / (getMass() / 1000) * FORCE_TIME; } public double getJumpTime(double jumpTimeStep) { diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 735852b..8eb79e3 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -480,13 +480,13 @@ public class Worm extends GameObject { */ public void move() throws IllegalArgumentException { - if (getWorld() == null) throw new IllegalStateException(); + if (getWorld() == null || getActionPoints() == 0) throw new IllegalStateException(); double newDirection = getFurthestLocationDirection(); Coordinate newLocation = getFurthestLocationInDirection(newDirection, this.getRadius()); double distance = getDistance(this.getLocation(), newLocation); - long cost = (long) round(abs(distance * cos(newDirection)) + abs(4 * distance * sin(newDirection))); + long cost = (long) Math.ceil(abs(distance * cos(newDirection)) + abs(4 * distance * sin(newDirection))); if (cost > getActionPoints()) throw new IllegalArgumentException(); @@ -522,16 +522,17 @@ public class Worm extends GameObject { if (step > radius) step = radius; Coordinate nextLoc = currentLocation; - while (getDistance(currentLocation, nextLoc) < maxDistance) { + while (getDistance(currentLocation, Coordinate.create(nextLoc.getX() + step * cos(direction), + nextLoc.getY() + step * sin(direction))) <= maxDistance) { - nextLoc = Coordinate.create(round((nextLoc.getX() + 0.1 * cos(direction)) * 100.0) / 100.0, - round((nextLoc.getY() + step * sin(direction)) * 100.0) / 100.0); + nextLoc = Coordinate.create(nextLoc.getX() + step * cos(direction), + nextLoc.getY() + step * sin(direction)); if (!world.isPassable(nextLoc.toArray(), radius)) { - double max = radius * 0.1 + 0.001; + double max = radius; while (!world.isAdjacent(nextLoc.toArray(), radius)) { max -= 0.01; - nextLoc = Coordinate.create(round((nextLoc.getX() - 0.01 * cos(direction)) * 100.0) / 100.0, - round((nextLoc.getY() - 0.01 * sin(direction)) * 100.0) / 100.0); + nextLoc = Coordinate.create(nextLoc.getX() - 0.01 * cos(direction), + nextLoc.getY() - 0.01 * sin(direction)); if (max < 0) { return currentLocation; } @@ -1229,7 +1230,7 @@ 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()) { + if (!getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) { List projectiles = getWorld().getGameObjectsByClass(Projectile.class); for (Projectile project: projectiles) { if (this.getDistance(project) < 0) { diff --git a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java index d0f9ad3..62c4e19 100755 --- a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java @@ -2437,7 +2437,10 @@ public class Part3_FullFacadeTest { double[] stepLocation = facade.getJumpStep(projectile, 0.1); double[] expectedRifleLocation = new double[] { 2.997, 9.275 }; double[] expectedBazookaLocation = new double[] { 6.114, 3.875 }; + System.out.println(projectile instanceof Rifle); assertEquals("Result must have exactly 2 coordinates", 2, stepLocation.length); + System.out.println(stepLocation[0] + " " + stepLocation[1]); + System.out.println(projectile.getLocationArray()[0] + " " + projectile.getLocationArray()[1]); assertTrue((Math.abs(stepLocation[0] - expectedRifleLocation[0]) < 0.01) || (Math.abs(stepLocation[0] - expectedBazookaLocation[0]) < 0.01)); assertTrue((Math.abs(stepLocation[1] - expectedRifleLocation[1]) < 0.01)