diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index 0554aea..7497fd7 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -36,7 +36,7 @@ public class Facade implements IFacade { try { worm.turn(angle); } - catch (AssertionError e) { + catch (AssertionError | IllegalArgumentException e) { throw new ModelException(e); } } @@ -359,7 +359,7 @@ public class Facade implements IFacade { */ @Override public double[] getJumpStep(Projectile projectile, double elapsedTime) { - return new double[0]; + return projectile.getJumpStep(elapsedTime).toArray(); } /** @@ -372,7 +372,7 @@ public class Facade implements IFacade { */ @Override public double getJumpTime(Projectile projectile, double jumpTimeStep) throws ModelException { - return 0; + return projectile.getJumpTime(jumpTimeStep); } /** @@ -386,7 +386,7 @@ public class Facade implements IFacade { */ @Override public void jump(Projectile projectile, double jumpTimeStep) throws ModelException { - + projectile.jump(jumpTimeStep); } /** diff --git a/OGP1718-Worms/src/worms/model/Projectile.java b/OGP1718-Worms/src/worms/model/Projectile.java index ef84032..cea10f9 100644 --- a/OGP1718-Worms/src/worms/model/Projectile.java +++ b/OGP1718-Worms/src/worms/model/Projectile.java @@ -82,7 +82,7 @@ public abstract class Projectile extends GameObject { return getForce()/getMass() * FORCE_TIME; } - private double getJumpTime(double jumpTimeStep) { + public double getJumpTime(double jumpTimeStep) { double v = jumpVelocity(); double time = jumpTimeStep; double a = getOrientation(); diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index fbb197d..735852b 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -249,7 +249,11 @@ public class Worm extends GameObject { */ @Raw private boolean canHaveAsRadius(double radius) { - return !Double.isNaN(radius) && radius >= getMinRadius() && !Double.isInfinite(radius); + if (getWorld() != null) { + return !Double.isNaN(radius) && radius >= getMinRadius() && !Double.isInfinite(radius) && getWorld().isPassable(getLocation(), radius); + } else { + return !Double.isNaN(radius) && radius >= getMinRadius() && !Double.isInfinite(radius); + } } /** @@ -1134,7 +1138,6 @@ public class Worm extends GameObject { } decreaseActionPoints(8); - setRadius(radius); World world = getWorld(); Coordinate location = getLocation(); @@ -1142,36 +1145,43 @@ public class Worm extends GameObject { Coordinate newLoc = Coordinate.create(location.getX() + changeRadius, location.getY()); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX() - changeRadius, location.getY()); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX(), location.getY() - changeRadius); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX(), location.getY() + changeRadius); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX() - changeRadius, location.getY() - changeRadius); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX() + changeRadius, location.getY() + changeRadius); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX() + changeRadius, location.getY() - changeRadius); if (world.isAdjacent(newLoc, radius)) { setLocation(newLoc); + setRadius(radius); return; } newLoc = Coordinate.create(location.getX() - changeRadius, location.getY() + changeRadius); @@ -1181,6 +1191,7 @@ public class Worm extends GameObject { } } setLocation(location); + setRadius(radius); } /** @@ -1221,7 +1232,7 @@ public class Worm extends GameObject { if (! getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) { List projectiles = getWorld().getGameObjectsByClass(Projectile.class); for (Projectile project: projectiles) { - if (this.getDistance(project) <= 0) { + if (this.getDistance(project) < 0) { project.hit(this); return null; } diff --git a/OGP1718-Worms/src/worms/programs/ProgramFactory.java b/OGP1718-Worms/src/worms/programs/ProgramFactory.java index 0d9f6cf..8bb7d1f 100644 --- a/OGP1718-Worms/src/worms/programs/ProgramFactory.java +++ b/OGP1718-Worms/src/worms/programs/ProgramFactory.java @@ -243,7 +243,7 @@ public class ProgramFactory implements IProgramFactory(Program::getWorm); + return Program::getWorm; } /** diff --git a/OGP1718-Worms/src/worms/programs/UnaryArgumentExpression.java b/OGP1718-Worms/src/worms/programs/UnaryArgumentExpression.java deleted file mode 100644 index 13c4b2a..0000000 --- a/OGP1718-Worms/src/worms/programs/UnaryArgumentExpression.java +++ /dev/null @@ -1,19 +0,0 @@ -package worms.programs; - -import worms.model.Program; - -import java.util.function.Function; - -public class UnaryArgumentExpression implements Expression { - - private final Function function; - - public UnaryArgumentExpression(Function unaryOperator) { - this.function = unaryOperator; - } - - @Override - public R execute(Program program) { - return function.apply(program); - } -} diff --git a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java index 795f9e8..39a4440 100755 --- a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java @@ -976,7 +976,7 @@ public class Part3_FullFacadeTest { @Test public void createWorm_IllegalWorld() { max_score += 2; - World someWorld = facade.createWorld(10.0, 10.0, map10x10); + World someWorld = facade.createWorld(10.0, 20.0, map10x10); facade.terminate(someWorld); try { facade.createWorm(someWorld, new double[] { 8.68, 8.68 }, 0.3, 0.3, "Worm", null);