package ch.epfl.xblast; /** * A Direction. * * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ 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(); } /** * 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; } } }