canFall in Worm en Facade

This commit is contained in:
Leen Dereu
2018-04-12 17:34:18 +02:00
parent afbdd5a88e
commit f9a13b9cfd
2 changed files with 8 additions and 3 deletions

View File

@@ -120,7 +120,7 @@ public class Facade implements IFacade {
*/
@Override
public boolean canFall(Worm worm) throws MustNotImplementException {
return false;
return worm.canFall();
}
/**

View File

@@ -832,14 +832,14 @@ public class Worm extends GameObject {
double[] center = {getLocation().getX(), getLocation().getY()};
Coordinate oldLocation = getLocation();
double endY = getLocation().getY();
if (! getWorld().isAdjacent(center, minRadius)) {
if (canFall()) {
for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) {
if (y >= (getWorld().getHeight() + 1)) {
terminate();
}
double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc);
if (getWorld().isAdjacent(center, minRadius)) {
if (! canFall()) {
endY = y;
break;
}
@@ -851,6 +851,11 @@ public class Worm extends GameObject {
decreaseHitPoints(cost);
}
public boolean canFall() {
double[] center = {getLocation().getX(), getLocation().getY()};
return ! getWorld().isAdjacent(center, minRadius);
}
public void collisionFall(Worm fallingWorm, Worm... worm) {
for (Worm stationaryWorm: worm) {
long value = stationaryWorm.getHitPoints()/2;