-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirection.java
More file actions
81 lines (79 loc) · 1.46 KB
/
Direction.java
File metadata and controls
81 lines (79 loc) · 1.46 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
73
74
75
76
77
78
79
80
81
/**
* @author Joseph Elsisi
* Direction represents the direction a person object is facing
*/
public enum Direction {
N, E, S, W, none;
/**
* @return the next direction to the right of the current direction
*/
public Direction cycle() { //turn this into a switch statment
if(this == N) {
return E;
}
else if(this == E){
return S;
}
else if(this == S) {
return W;
}
else if(this == W) {
return N;
}
else {
return none;
}
}
/**
* @return the opposite direction of the current direction
*/
public Direction getOpposite(){
if(this == N) {
return S;
}
else if(this == E){
return W;
}
else if(this == S) {
return N;
}
else if(this == W) {
return E;
}
else {
return none;
}
}
/**
* @param other is a given Direction
* @return true/false depending on whether the Direction is opposite to the current Direction
*/
public boolean isOpposite(Direction other) {
if(this == N) {
if(other.getOpposite() == N) {
return true;
}
}
else if(this == E){
if(other.getOpposite() == E) {
return true;
}
}
else if(this == S) {
if(other.getOpposite() == S) {
return true;
}
}
else if(this == W) {
if(other.getOpposite() == W) {
return true;
}
}
else if(this == none) {
if(other.getOpposite() == none) {
return true;
}
}
return false;
}
}