diff --git a/src/main/java/ch/fritteli/labyrinth/generator/Generator.java b/src/main/java/ch/fritteli/labyrinth/generator/Generator.java index fa6c687..45b3f9c 100644 --- a/src/main/java/ch/fritteli/labyrinth/generator/Generator.java +++ b/src/main/java/ch/fritteli/labyrinth/generator/Generator.java @@ -31,21 +31,24 @@ public class Generator { } private void preDig() { + final Position end = this.labyrinth.getEnd(); final Tile endTile = this.labyrinth.getEndTile(); - if (endTile.hasWallAt(Direction.BOTTOM)) { - endTile.enableDiggingToOrFrom(Direction.BOTTOM); - endTile.digFrom(Direction.BOTTOM); - } else if (endTile.hasWallAt(Direction.RIGHT)) { - endTile.enableDiggingToOrFrom(Direction.RIGHT); - endTile.digFrom(Direction.RIGHT); - } else if (endTile.hasWallAt(Direction.TOP)) { + + if (end.getY() == 0) { endTile.enableDiggingToOrFrom(Direction.TOP); endTile.digFrom(Direction.TOP); - } else if (endTile.hasWallAt(Direction.LEFT)) { + } else if (end.getX() == 0) { endTile.enableDiggingToOrFrom(Direction.LEFT); endTile.digFrom(Direction.LEFT); + } else if (end.getY() == this.labyrinth.getHeight() - 1) { + endTile.enableDiggingToOrFrom(Direction.BOTTOM); + endTile.digFrom(Direction.BOTTOM); + } else if (end.getX() == this.labyrinth.getWidth() - 1) { + endTile.enableDiggingToOrFrom(Direction.RIGHT); + endTile.digFrom(Direction.RIGHT); } - this.positions.push(this.labyrinth.getEnd()); + + this.positions.push(end); } private void dig() { @@ -80,17 +83,19 @@ public class Generator { } private void postDig() { + final Position start = this.labyrinth.getStart(); final Tile startTile = this.labyrinth.getStartTile(); - if (startTile.hasWallAt(Direction.TOP)) { + + if (start.getY() == 0) { startTile.enableDiggingToOrFrom(Direction.TOP); startTile.digTo(Direction.TOP); - } else if (startTile.hasWallAt(Direction.LEFT)) { + } else if (start.getX() == 0) { startTile.enableDiggingToOrFrom(Direction.LEFT); startTile.digTo(Direction.LEFT); - } else if (startTile.hasWallAt(Direction.BOTTOM)) { + } else if (start.getY() == this.labyrinth.getHeight() - 1) { startTile.enableDiggingToOrFrom(Direction.BOTTOM); startTile.digTo(Direction.BOTTOM); - } else if (startTile.hasWallAt(Direction.RIGHT)) { + } else if (start.getX() == this.labyrinth.getWidth() - 1) { startTile.enableDiggingToOrFrom(Direction.RIGHT); startTile.digTo(Direction.RIGHT); } diff --git a/src/main/java/ch/fritteli/labyrinth/generator/model/Labyrinth.java b/src/main/java/ch/fritteli/labyrinth/generator/model/Labyrinth.java index ddb93ca..de92154 100644 --- a/src/main/java/ch/fritteli/labyrinth/generator/model/Labyrinth.java +++ b/src/main/java/ch/fritteli/labyrinth/generator/model/Labyrinth.java @@ -45,7 +45,7 @@ public class Labyrinth { throw new IllegalArgumentException("'start' must be at the edge of the labyrinth"); } if (end.getX() != 0 && end.getX() != width - 1 && end.getY() != 0 && end.getY() != height - 1) { - throw new IllegalArgumentException("'start' must be at the edge of the labyrinth"); + throw new IllegalArgumentException("'end' must be at the edge of the labyrinth"); } this.width = width; this.height = height;