blob: e9d596158a2b25007911c71470efde8b4759b997 (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
package ch.epfl.xblast;
/**
* A Direction.
*
* @author Pacien TRAN-GIRARD (261948)
*/
public enum Direction {
/**
* North
*/
N,
/**
* East
*/
E,
/**
* South
*/
S,
/**
* West
*/
W;
/**
* Returns the opposite Direction.
*
* @return the opposite Direction
*/
public Direction opposite() {
switch (this) {
case N:
return S;
case S:
return N;
case E:
return W;
case W:
return E;
default:
return null;
}
}
/**
* T(the Direction is horizontal to the screen (East or West)).
*
* @return T(the Direction is horizontal to the screen)
*/
public boolean isHorizontal() {
return this == E || this == W;
}
/**
* T(the current and given Directions are parallel (identical or opposite)).
*
* @param that a Direction to compare
* @return T(the current and given Directions are parallel)
*/
public boolean isParallelTo(Direction that) {
return that == this || that == this.opposite();
}
/**
* Returns the x-coordinate of the normed vector representation of the Direction.
*
* @return the x-coordinate
*/
public int xVector() {
switch (this) {
case W:
return -1;
case E:
return +1;
default:
return 0;
}
}
/**
* Returns the x-coordinate of the normed vector representation of the Direction.
*
* @return the y-coordinate
*/
public int yVector() {
switch (this) {
case N:
return -1;
case S:
return +1;
default:
return 0;
}
}
}
|