fixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
||||
for (Projectile project: projectiles) {
|
||||
if (this.getDistance(project) < 0) {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user