small fixes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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();
|
||||
|
@@ -249,8 +249,12 @@ public class Worm extends GameObject {
|
||||
*/
|
||||
@Raw
|
||||
private boolean canHaveAsRadius(double 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mass of the worm.
|
||||
@@ -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<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
||||
for (Projectile project: projectiles) {
|
||||
if (this.getDistance(project) <= 0) {
|
||||
if (this.getDistance(project) < 0) {
|
||||
project.hit(this);
|
||||
return null;
|
||||
}
|
||||
|
@@ -243,7 +243,7 @@ public class ProgramFactory implements IProgramFactory<Expression, Statement, Pr
|
||||
@Override
|
||||
public Expression createSelfExpression(SourceLocation location) throws ModelException {
|
||||
|
||||
return new UnaryArgumentExpression<Worm>(Program::getWorm);
|
||||
return Program::getWorm;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,19 +0,0 @@
|
||||
package worms.programs;
|
||||
|
||||
import worms.model.Program;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class UnaryArgumentExpression<R> implements Expression<R> {
|
||||
|
||||
private final Function<Program, R> function;
|
||||
|
||||
public UnaryArgumentExpression(Function<Program, R> unaryOperator) {
|
||||
this.function = unaryOperator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R execute(Program program) {
|
||||
return function.apply(program);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user