fixes
This commit is contained in:
@@ -30,7 +30,7 @@ public class Bazooka extends Projectile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double calcForce(double actionPoints) {
|
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;
|
if (hp > 9.5) return 9.5;
|
||||||
return hp;
|
return hp;
|
||||||
}
|
}
|
||||||
|
@@ -123,7 +123,7 @@ public class Program {
|
|||||||
case MOVE:
|
case MOVE:
|
||||||
try {
|
try {
|
||||||
actionHandler.move(worm);
|
actionHandler.move(worm);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||||
enoughAP = false;
|
enoughAP = false;
|
||||||
callStack.push(new CallStackNode(null, s));
|
callStack.push(new CallStackNode(null, s));
|
||||||
return;
|
return;
|
||||||
|
@@ -69,17 +69,17 @@ public abstract class Projectile extends GameObject {
|
|||||||
public static final double FORCE_TIME = 0.5;
|
public static final double FORCE_TIME = 0.5;
|
||||||
|
|
||||||
public Coordinate getJumpStep(double elapsedTime) {
|
public Coordinate getJumpStep(double elapsedTime) {
|
||||||
if (Double.isNaN(elapsedTime) || elapsedTime > this.getJumpTime(elapsedTime) || elapsedTime < 0)
|
if (Double.isNaN(elapsedTime) || elapsedTime < 0)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
double velocity = this.jumpVelocity();
|
double velocity = this.jumpVelocity();
|
||||||
|
|
||||||
return Coordinate.create(getLocation().getX() + velocity * cos(getOrientation()) * elapsedTime,
|
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() {
|
private double jumpVelocity() {
|
||||||
return getForce()/getMass() * FORCE_TIME;
|
return getForce() / (getMass() / 1000) * FORCE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getJumpTime(double jumpTimeStep) {
|
public double getJumpTime(double jumpTimeStep) {
|
||||||
|
@@ -480,13 +480,13 @@ public class Worm extends GameObject {
|
|||||||
*/
|
*/
|
||||||
public void move() throws IllegalArgumentException {
|
public void move() throws IllegalArgumentException {
|
||||||
|
|
||||||
if (getWorld() == null) throw new IllegalStateException();
|
if (getWorld() == null || getActionPoints() == 0) throw new IllegalStateException();
|
||||||
|
|
||||||
double newDirection = getFurthestLocationDirection();
|
double newDirection = getFurthestLocationDirection();
|
||||||
Coordinate newLocation = getFurthestLocationInDirection(newDirection, this.getRadius());
|
Coordinate newLocation = getFurthestLocationInDirection(newDirection, this.getRadius());
|
||||||
double distance = getDistance(this.getLocation(), newLocation);
|
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())
|
if (cost > getActionPoints())
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@@ -522,16 +522,17 @@ public class Worm extends GameObject {
|
|||||||
if (step > radius) step = radius;
|
if (step > radius) step = radius;
|
||||||
Coordinate nextLoc = currentLocation;
|
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,
|
nextLoc = Coordinate.create(nextLoc.getX() + step * cos(direction),
|
||||||
round((nextLoc.getY() + step * sin(direction)) * 100.0) / 100.0);
|
nextLoc.getY() + step * sin(direction));
|
||||||
if (!world.isPassable(nextLoc.toArray(), radius)) {
|
if (!world.isPassable(nextLoc.toArray(), radius)) {
|
||||||
double max = radius * 0.1 + 0.001;
|
double max = radius;
|
||||||
while (!world.isAdjacent(nextLoc.toArray(), radius)) {
|
while (!world.isAdjacent(nextLoc.toArray(), radius)) {
|
||||||
max -= 0.01;
|
max -= 0.01;
|
||||||
nextLoc = Coordinate.create(round((nextLoc.getX() - 0.01 * cos(direction)) * 100.0) / 100.0,
|
nextLoc = Coordinate.create(nextLoc.getX() - 0.01 * cos(direction),
|
||||||
round((nextLoc.getY() - 0.01 * sin(direction)) * 100.0) / 100.0);
|
nextLoc.getY() - 0.01 * sin(direction));
|
||||||
if (max < 0) {
|
if (max < 0) {
|
||||||
return currentLocation;
|
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 location overlaps with 1 or more projectiles => firing worm is hit by one overlapping projectile
|
||||||
//TODO => method returns null
|
//TODO => method returns null
|
||||||
if (! getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) {
|
if (!getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) {
|
||||||
List<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
List<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
||||||
for (Projectile project: projectiles) {
|
for (Projectile project: projectiles) {
|
||||||
if (this.getDistance(project) < 0) {
|
if (this.getDistance(project) < 0) {
|
||||||
|
@@ -2437,7 +2437,10 @@ public class Part3_FullFacadeTest {
|
|||||||
double[] stepLocation = facade.getJumpStep(projectile, 0.1);
|
double[] stepLocation = facade.getJumpStep(projectile, 0.1);
|
||||||
double[] expectedRifleLocation = new double[] { 2.997, 9.275 };
|
double[] expectedRifleLocation = new double[] { 2.997, 9.275 };
|
||||||
double[] expectedBazookaLocation = new double[] { 6.114, 3.875 };
|
double[] expectedBazookaLocation = new double[] { 6.114, 3.875 };
|
||||||
|
System.out.println(projectile instanceof Rifle);
|
||||||
assertEquals("Result must have exactly 2 coordinates", 2, stepLocation.length);
|
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)
|
assertTrue((Math.abs(stepLocation[0] - expectedRifleLocation[0]) < 0.01)
|
||||||
|| (Math.abs(stepLocation[0] - expectedBazookaLocation[0]) < 0.01));
|
|| (Math.abs(stepLocation[0] - expectedBazookaLocation[0]) < 0.01));
|
||||||
assertTrue((Math.abs(stepLocation[1] - expectedRifleLocation[1]) < 0.01)
|
assertTrue((Math.abs(stepLocation[1] - expectedRifleLocation[1]) < 0.01)
|
||||||
|
Reference in New Issue
Block a user