From a68fa3c3c96c38b811755022089cb8aee2f5521c Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 29 May 2015 12:06:42 +0200 Subject: Intermediate commit: works partially, but sometimes cars go over each other (Crossing.isAllowed() is not synchronized) --- Week14 Route 66/src/OO14route66/Direction.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Week14 Route 66/src/OO14route66/Direction.java') diff --git a/Week14 Route 66/src/OO14route66/Direction.java b/Week14 Route 66/src/OO14route66/Direction.java index b8c1636..14d7110 100644 --- a/Week14 Route 66/src/OO14route66/Direction.java +++ b/Week14 Route 66/src/OO14route66/Direction.java @@ -37,6 +37,21 @@ public enum Direction } } } + + /** + * Get the opposite of a direction + * @param direction + * @return + */ + public static Direction opposite(Direction direction) { + switch (direction) { + case North: return South; + case South: return North; + case East: return West; + case West: return East; + default: return direction; + } + } /** * override standard toString -- cgit v1.2.3