This commit is contained in:
2018-05-22 15:39:22 +02:00
parent 63cabe27fc
commit 20bc7330f6
5 changed files with 18 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {