-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathRow.java
More file actions
72 lines (55 loc) · 1.51 KB
/
Row.java
File metadata and controls
72 lines (55 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package chess;
import java.util.Arrays;
public enum Row {
EIGHT("8"),
SEVEN("7"),
SIX("6"),
FIVE("5"),
FOUR("4"),
THREE("3"),
TWO("2"),
ONE("1");
private final String text;
Row(final String text) {
this.text = text;
}
public static Row of(final String text) {
return Arrays.stream(values())
.filter(value -> value.text.equals(text))
.findAny()
.orElseThrow();
}
public static int calculateDiff(Row row, Row otherRow) {
return Integer.parseInt(otherRow.text) - Integer.parseInt(row.text);
}
public boolean isTop() {
return ordinal() == 0;
}
public boolean isBottom() {
return ordinal() + 1 == values().length;
}
public boolean canMoveUp(final int step) {
return ordinal() - step >= 0;
}
public Row moveUp() {
return moveUp(1);
}
public Row moveUp(final int step) {
if (canMoveUp(step)) {
return values()[ordinal() - step];
}
throw new IllegalStateException("움직일 수 없는 위치입니다.");
}
public boolean canMoveDown(final int step) {
return ordinal() + step < values().length;
}
public Row moveDown() {
return moveDown(1);
}
public Row moveDown(final int step) {
if (canMoveDown(step)) {
return values()[ordinal() + step];
}
throw new IllegalStateException("움직일 수 없는 위치입니다.");
}
}