28 lines
719 B
Java
28 lines
719 B
Java
package ch.fritteli.maze.generator.model;
|
|
|
|
import lombok.NonNull;
|
|
import lombok.Value;
|
|
import lombok.With;
|
|
|
|
@Value
|
|
@With
|
|
public class Position {
|
|
int x;
|
|
int y;
|
|
|
|
public Position move(@NonNull final Direction direction) {
|
|
switch (direction) {
|
|
case BOTTOM:
|
|
return this.withY(this.y + 1);
|
|
case LEFT:
|
|
return this.withX(this.x - 1);
|
|
case RIGHT:
|
|
return this.withX(this.x + 1);
|
|
case TOP:
|
|
return this.withY(this.y - 1);
|
|
default:
|
|
throw new IllegalStateException("Programming error: Not all Direction enum values covered in Position#move(Direction)!");
|
|
}
|
|
}
|
|
}
|