Created boat initialise method to run through boats setting correct start position

- Running funny, try pulling changes from master

#story[20]
main
Erika Savell 9 years ago
parent d15cd2b881
commit 176b644aaf

@ -79,6 +79,10 @@ public class Leg {
} }
public void setStartGPSCoordinate(GPSCoordinate startGPSCoordinate) {
this.startGPSCoordinate = startGPSCoordinate;
}
public GPSCoordinate getStartMarker1() { public GPSCoordinate getStartMarker1() {
return startMarker1; return startMarker1;
} }
@ -95,6 +99,12 @@ public class Leg {
return endMarker2; 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. * Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
@ -143,10 +153,12 @@ public class Leg {
private void calculateStart() { private void calculateStart() {
//TO DO: Make this function set the start node as halfway between the two markers //TO DO: Make this function set the start node as halfway between the two markers
this.startGPSCoordinate = startMarker1;
} }
private void calculateEnd() { private void calculateEnd() {
//TO DO: Make this function set the end node as halfway between the two markers //TO DO: Make this function set the end node as halfway between the two markers
this.endGPSCoordinate = endMarker1;
} }
} }

@ -42,26 +42,11 @@ public abstract class Race implements Runnable {
this.legs.add(new Leg("Finish", this.legs.size())); this.legs.add(new Leg("Finish", this.legs.size()));
this.controller = controller; this.controller = controller;
this.scaleFactor = scaleFactor; this.scaleFactor = scaleFactor;
if (startingBoats != null && startingBoats.size() > 0){
initialiseBoats(); 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);
}
}
} }
} }
/** /**
* Constructor for Race class * 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<GPSCoordinate> 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. * Runnable for the thread.
*/ */

Loading…
Cancel
Save