diff options
author | Pacien TRAN-GIRARD | 2016-02-22 13:19:27 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-02-22 13:19:27 +0100 |
commit | cabd0bd13781c85df2bcbc3f9cb6d9270800127c (patch) | |
tree | 1e5c5bbcd6ecaf9a79d25071d841f99386b0313e /src/ch/epfl | |
parent | b34201af08ea72df171751dda1df3e3b1b9a45d1 (diff) | |
download | xblast-cabd0bd13781c85df2bcbc3f9cb6d9270800127c.tar.gz |
Implement Direction enum
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/xblast/Direction.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/Direction.java b/src/ch/epfl/xblast/Direction.java new file mode 100644 index 0000000..ea0960d --- /dev/null +++ b/src/ch/epfl/xblast/Direction.java | |||
@@ -0,0 +1,51 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | /** | ||
4 | * A Direction. | ||
5 | * | ||
6 | * @author Pacien TRAN-GIRARD (261948) | ||
7 | */ | ||
8 | public enum Direction { | ||
9 | |||
10 | N, E, S, W; | ||
11 | |||
12 | /** | ||
13 | * Returns the opposite Direction. | ||
14 | * | ||
15 | * @return the opposite Direction | ||
16 | */ | ||
17 | public Direction opposite() { | ||
18 | switch (this) { | ||
19 | case N: | ||
20 | return S; | ||
21 | case S: | ||
22 | return N; | ||
23 | case E: | ||
24 | return W; | ||
25 | case W: | ||
26 | return E; | ||
27 | default: | ||
28 | return null; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * T(the Direction is horizontal to the screen (East or West)). | ||
34 | * | ||
35 | * @return T(the Direction is horizontal to the screen) | ||
36 | */ | ||
37 | public boolean isHorizontal() { | ||
38 | return this == E || this == W; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * T(the current and given Directions are parallel (identical or opposite)). | ||
43 | * | ||
44 | * @param that a Direction to compare | ||
45 | * @return T(the current and given Directions are parallel) | ||
46 | */ | ||
47 | public boolean isParallelTo(Direction that) { | ||
48 | return that == this || that == this.opposite(); | ||
49 | } | ||
50 | |||
51 | } | ||