aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/Direction.java
blob: b8852dec0452f366cb9c8bd48b29739a9cc31bf8 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package ch.epfl.xblast;

/**
 * Directions.
 *
 * @author Pacien TRAN-GIRARD (261948)
 * @author Timothée FLOURE (257420)
 */
public enum Direction {

    /**
     * North
     */
    N,

    /**
     * East
     */
    E,

    /**
     * South
     */
    S,

    /**
     * West
     */
    W;

    /**
     * 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 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 current and given Directions are perpendicular).
     *
     * @param that a Direction to compare
     * @return T(the current and given Directions are perpendicular)
     */
    public boolean isPerpendicularTo(Direction that) {
        switch (this) {
            case N:
            case S:
                return that == E || that == W;
            case E:
            case W:
                return that == N || that == S;
            default:
                return false;
        }
    }

    /**
     * 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;
        }
    }

}