From 3af159af069c8fcd75d78160991c29abd2eb1fc9 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 22 Feb 2020 22:31:47 +0100 Subject: [PATCH] Legger til en metode for revers retning i Direction --- .../element_properties/Direction.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/element_properties/Direction.java b/src/main/java/inf112/fiasko/roborally/element_properties/Direction.java index 864b974..b6e21bd 100644 --- a/src/main/java/inf112/fiasko/roborally/element_properties/Direction.java +++ b/src/main/java/inf112/fiasko/roborally/element_properties/Direction.java @@ -44,4 +44,32 @@ public enum Direction { } return null; } + + /** + * Gets the reverse of a direction + * @param direction A direction + * @return The reverse direction + */ + public static Direction getReverseDirection(Direction direction) { + switch (direction) { + case NORTH: + return SOUTH; + case SOUTH: + return NORTH; + case EAST: + return WEST; + case WEST: + return EAST; + case NORTH_EAST: + return SOUTH_WEST; + case NORTH_WEST: + return SOUTH_EAST; + case SOUTH_WEST: + return NORTH_EAST; + case SOUTH_EAST: + return NORTH_WEST; + default: + throw new IllegalArgumentException("Invalid input direction."); + } + } } \ No newline at end of file