updated facade and world

This commit is contained in:
2018-04-03 15:35:56 +02:00
parent dd0b0017d4
commit c4a4bd9c2e
2 changed files with 65 additions and 6 deletions

View File

@@ -115,6 +115,23 @@ public class Facade implements IFacade {
} }
/**
* Returns whether the given worm can fall.
*/
@Override
public boolean canFall(Worm worm) throws MustNotImplementException {
return false;
}
/**
* Makes the given worm fall down until it rests on impassable terrain again,
* or until it leaves the world in which it is in.
*/
@Override
public void fall(Worm worm) throws ModelException, MustNotImplementException {
}
/** /**
* Return the time needed by the given worm to jump to the nearest position * Return the time needed by the given worm to jump to the nearest position
* adjacent to impassable terrain. * adjacent to impassable terrain.

View File

@@ -1,7 +1,5 @@
package worms.model; package worms.model;
import java.util.ArrayList;
public class World { public class World {
private boolean terminated = false; private boolean terminated = false;
@@ -14,6 +12,9 @@ public class World {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.map = map; this.map = map;
lengthX = width / map[0].length;
lengthY = height / map.length;
} }
@@ -40,21 +41,62 @@ public class World {
// region map // region map
//=================================================================================== //===================================================================================
private final double lengthX;
private final double lengthY;
public boolean[][] getMap() { public boolean[][] getMap() {
return map; return map;
} }
public boolean isPassable(double[] location) { public boolean isPassable(double[] location) {
if (location[0] >= getMap()[0].length || location[0] < 0.0 || if (location[0] / lengthX >= getMap()[0].length || location[0] < 0.0 ||
location[1] >= getMap().length || location[1] < 0.0) { location[1] / lengthY >= getMap().length || location[1] < 0.0) {
return true; return true;
} }
return this.map[(int) Math.round(location[0])][(int) Math.round(location[1])]; return this.map[(int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)];
}
private boolean isPassable(double x, double y) {
int xCoord = (int) Math.floor(x / lengthX);
int yCoord = (int) Math.floor(y / lengthY);
return this.map[yCoord][xCoord];
}
private boolean canHaveAsPartialCircle(double x, double y, double[] center) {
if (!isPassable(x + center[0], y + center[1])) return false;
x *= -1;
if (!isPassable(x + center[0], y + center[1])) return false;
y *= -1;
if (!isPassable(x + center[0], y + center[1])) return false;
x *= -1;
return isPassable(x + center[0], y + center[1]);
} }
public boolean isPassable(double[] center, double radius) { public boolean isPassable(double[] center, double radius) {
return false;
int radX = (int) Math.floor(radius / lengthX);
for (int x = 0, y = 0; x <= radX; x++, y++) {
double realX = x * radius;
double realY = Math.sqrt(Math.pow(radius, 2) - Math.pow(realX, 2));
if (canHaveAsPartialCircle(realX, realY, center)) return false;
realY = y * radius;
realX = Math.sqrt(Math.pow(radius, 2) + center[0] - Math.pow(realY, 2) + center[1]);
if (canHaveAsPartialCircle(realX, realY, center)) return false;
}
return true;
}
public boolean isAdjacent(double[] center, double radius) {
double maxDistance = radius * 0.1;
double length = lengthX;
if (lengthX > lengthY) length = lengthY;
return isPassable(center, radius) && !isPassable(center, radius + maxDistance + length);
} }
public boolean isTerminated() { public boolean isTerminated() {