diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index 48a8898..300ed6c 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -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 * adjacent to impassable terrain. diff --git a/OGP1718-Worms/src/worms/model/World.java b/OGP1718-Worms/src/worms/model/World.java index d56a08f..d2261a6 100644 --- a/OGP1718-Worms/src/worms/model/World.java +++ b/OGP1718-Worms/src/worms/model/World.java @@ -1,7 +1,5 @@ package worms.model; -import java.util.ArrayList; - public class World { private boolean terminated = false; @@ -14,6 +12,9 @@ public class World { this.width = width; this.height = height; this.map = map; + + lengthX = width / map[0].length; + lengthY = height / map.length; } @@ -40,21 +41,62 @@ public class World { // region map //=================================================================================== + private final double lengthX; + private final double lengthY; public boolean[][] getMap() { return map; } public boolean isPassable(double[] location) { - if (location[0] >= getMap()[0].length || location[0] < 0.0 || - location[1] >= getMap().length || location[1] < 0.0) { + if (location[0] / lengthX >= getMap()[0].length || location[0] < 0.0 || + location[1] / lengthY >= getMap().length || location[1] < 0.0) { 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) { - 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() {