mirror of
https://codeberg.org/JasterV/uni-lab.git
synced 2026-04-26 18:40:03 +00:00
27 lines
804 B
Java
27 lines
804 B
Java
public class Direction {
|
|
|
|
public static final Direction UP = new Direction(0, -1);
|
|
public static final Direction RIGHT = new Direction(1, 0);
|
|
public static final Direction DOWN = new Direction(0, 1);
|
|
public static final Direction LEFT = new Direction(-1, 0);
|
|
|
|
public static final Direction[] ALL = new Direction[]{UP, RIGHT, DOWN, LEFT};
|
|
|
|
private final int dx;
|
|
private final int dy;
|
|
|
|
private Direction(int dx, int dy) {
|
|
this.dx = dx;
|
|
this.dy = dy;
|
|
}
|
|
|
|
public Position apply(Position from) {
|
|
return new Position(from.getX() + dx,
|
|
from.getY() + dy);
|
|
}
|
|
|
|
public Position apply2Times(Position from) {
|
|
return new Position(from.getX() + dx * 2,
|
|
from.getY() + dy * 2);
|
|
}
|
|
}
|