diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Color.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Color.java index 218416a6..828450f4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Color.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Color.java @@ -26,16 +26,33 @@ public enum Color { */ NONE; + /** + * This method will be used to return a Color enumeration depending on the given index parameter. + * + * @param index as the index of the color inside the values as an Integer. + * @return a Color enumeration. + */ + public static Color getColorByIndex(int index) { + if (index < 0 || index >= values().length) { + throw new IllegalArgumentException(""); + } + + return values()[index]; + } + /** * This method will be used to calculate the next color inside the sequence. * * @return color as a Color Enumeration. */ public Color next() { - if (this.next() == NONE) { - return AIRFORCE; + Color[] colors = values(); + int nextIndex = (this.ordinal() + 1) % colors.length; + + if (colors[nextIndex] == NONE) { + nextIndex = (nextIndex + 1) % colors.length; } - return values()[(ordinal() + 1) % values().length]; + return colors[nextIndex]; } }