feature/make-start-and-end-configurable #7

Merged
manuel merged 2 commits from feature/make-start-and-end-configurable into master 2023-04-17 00:19:05 +02:00
2 changed files with 19 additions and 14 deletions
Showing only changes of commit 31b7fd6b2a - Show all commits

View file

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

View file

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