diff --git a/src/main/java/seng302/Model/Leg.java b/src/main/java/seng302/Model/Leg.java index e396e8d7..a7514fab 100644 --- a/src/main/java/seng302/Model/Leg.java +++ b/src/main/java/seng302/Model/Leg.java @@ -79,6 +79,10 @@ public class Leg { } + public void setStartGPSCoordinate(GPSCoordinate startGPSCoordinate) { + this.startGPSCoordinate = startGPSCoordinate; + } + public GPSCoordinate getStartMarker1() { return startMarker1; } @@ -95,6 +99,12 @@ public class Leg { return endMarker2; } + public Leg createCopy() { + Leg copy = new Leg(this.name, this.startMarker1, this.startMarker2, + this.endMarker1, this.endMarker2, this.legNumber); + return copy; + } + /** * Returns the coordinates in GPSCoordinate class of the boats starting coordinate. @@ -143,10 +153,12 @@ public class Leg { private void calculateStart() { //TO DO: Make this function set the start node as halfway between the two markers + this.startGPSCoordinate = startMarker1; } private void calculateEnd() { //TO DO: Make this function set the end node as halfway between the two markers + this.endGPSCoordinate = endMarker1; } } diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 9016cea4..b30f87cb 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -42,26 +42,11 @@ public abstract class Race implements Runnable { this.legs.add(new Leg("Finish", this.legs.size())); this.controller = controller; this.scaleFactor = scaleFactor; - - initialiseBoats(); - } - - - private void initialiseBoats() { - Leg startLeg = legs.get(0); - - - - if (startingBoats.size() > 0) { - for (BoatInRace boat : startingBoats) { - if (boat != null) { - boat.setScaledVelocity(boat.getVelocity() * scaleFactor); - - boat.setCurrentLeg(startLeg); - } - } + if (startingBoats != null && startingBoats.size() > 0){ + initialiseBoats(); } } + /** * Constructor for Race class * @@ -83,6 +68,21 @@ public abstract class Race implements Runnable { } + protected void initialiseBoats() { + System.out.println("boat initialisation"); + Leg startLeg = legs.get(0); + Leg copyLeg = startLeg.createCopy(); + ArrayList startPositions = getSpreadStartingPositions(); + for (int i = 0; i < startingBoats.size(); i++) { + BoatInRace boat = startingBoats.get(i); + if (boat != null) { + boat.setScaledVelocity(boat.getVelocity() * scaleFactor); + copyLeg.setStartGPSCoordinate(startPositions.get(i)); + boat.setCurrentLeg(startLeg); + } + } + } + /** * Runnable for the thread. */