From cabd0bd13781c85df2bcbc3f9cb6d9270800127c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 22 Feb 2016 13:19:27 +0100 Subject: Implement Direction enum --- src/ch/epfl/xblast/Direction.java | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/ch/epfl/xblast/Direction.java 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 @@ +package ch.epfl.xblast; + +/** + * A Direction. + * + * @author Pacien TRAN-GIRARD (261948) + */ +public enum Direction { + + N, E, S, 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(); + } + +} -- cgit v1.2.3