diff --git a/src/main/java/seng302/models/Boat.java b/src/main/java/seng302/models/Boat.java index 8948bedd..8deb5339 100644 --- a/src/main/java/seng302/models/Boat.java +++ b/src/main/java/seng302/models/Boat.java @@ -1,5 +1,7 @@ package seng302.models; +import javafx.scene.paint.Color; + /** * Represents a boat in the race. */ @@ -10,6 +12,7 @@ public class Boat { private double lat; // Boats position private double lon; // - private double distanceToNextMark; + private Color color; public Boat(String teamName) { this.teamName = teamName; @@ -17,6 +20,7 @@ public class Boat { this.lat = 0.0; this.lon = 0.0; this.distanceToNextMark = 0.0; + this.color = Colors.getColor(); } /** @@ -89,4 +93,8 @@ public class Boat { public double getLongitude(){ return this.lon; } + + public Color getColor() { + return color; + } } \ No newline at end of file diff --git a/src/main/java/seng302/models/Colors.java b/src/main/java/seng302/models/Colors.java new file mode 100644 index 00000000..419753dc --- /dev/null +++ b/src/main/java/seng302/models/Colors.java @@ -0,0 +1,20 @@ +package seng302.models; + +import javafx.scene.paint.Color; + +/** + * Created by ryan_ on 16/03/2017. + */ +public enum Colors { + RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE; + + static Integer index = 0; + + public static Color getColor() { + index++; + if (index > 6) { + index = 1; + } + return Color.valueOf(values()[index-1].toString()); + } +} diff --git a/src/test/java/seng302/ColorsTest.java b/src/test/java/seng302/ColorsTest.java new file mode 100644 index 00000000..8fcc2399 --- /dev/null +++ b/src/test/java/seng302/ColorsTest.java @@ -0,0 +1,45 @@ +package seng302; + +import javafx.scene.paint.Color; +import org.junit.Test; +import seng302.models.Boat; +import seng302.models.Colors; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +/** + * Created by ryan_ on 16/03/2017. + */ +public class ColorsTest { + @Test + public void testNextColor() { + List boats = new ArrayList<>(); + boats.add(new Boat("Team 1")); + boats.add(new Boat("Team 2")); + boats.add(new Boat("Team 3")); + boats.add(new Boat("Team 4")); + boats.add(new Boat("Team 5")); + boats.add(new Boat("Team 6")); + + int count = 0; + List enumColors = new ArrayList<>(); + while (count < 6) { + Color color = Colors.getColor(); + enumColors.add(color); + count++; + } + + List boatColors = new ArrayList<>(); + for (Boat boat : boats) { + Color color = boat.getColor(); + boatColors.add(color); + } + + assertEquals(enumColors, boatColors); + } +}