Add tests and add validity check to labyrinth dimensions.
This commit is contained in:
parent
15f93310e4
commit
ad0759b36f
3 changed files with 192 additions and 6 deletions
|
@ -2,21 +2,22 @@ package ch.fritteli.labyrinth.model;
|
|||
|
||||
public enum Direction {
|
||||
TOP,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
LEFT,
|
||||
RIGHT;
|
||||
LEFT;
|
||||
|
||||
public Direction invert() {
|
||||
switch (this) {
|
||||
case TOP:
|
||||
return BOTTOM;
|
||||
case LEFT:
|
||||
return RIGHT;
|
||||
case RIGHT:
|
||||
return LEFT;
|
||||
case BOTTOM:
|
||||
return TOP;
|
||||
case LEFT:
|
||||
return RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException("Programming error: Not all enum values covered in enum Direction#invert()!");
|
||||
}
|
||||
throw new IllegalStateException("Programming error: Not all enum values covered in enum Direction#invert()!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,13 @@ public class Labyrinth {
|
|||
}
|
||||
|
||||
public Labyrinth(final int width, final int height, final long randomSeed) {
|
||||
if (width <= 0 || height <= 0) {
|
||||
throw new IllegalArgumentException("widht and height must be >=1");
|
||||
}
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.randomSeed = randomSeed;
|
||||
this.random = new Random(this.randomSeed);
|
||||
this.random = new Random(randomSeed);
|
||||
this.field = new Tile[width][height];
|
||||
this.start = new Position(0, 0);
|
||||
this.end = new Position(this.width - 1, this.height - 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue