|
|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package seng302.Model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableArray;
|
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
import seng302.Controllers.RaceController;
|
|
|
|
|
import seng302.GPSCoordinate;
|
|
|
|
|
|
|
|
|
|
@ -11,7 +14,8 @@ import java.util.*;
|
|
|
|
|
* Created by fwy13 on 3/03/17.
|
|
|
|
|
*/
|
|
|
|
|
public abstract class Race implements Runnable {
|
|
|
|
|
protected ArrayList<BoatInRace> startingBoats;
|
|
|
|
|
//protected BoatInRace[] startingBoats;
|
|
|
|
|
protected ObservableList<BoatInRace> startingBoats;
|
|
|
|
|
protected ArrayList<Leg> legs;
|
|
|
|
|
protected RaceController controller;
|
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
|
@ -24,14 +28,14 @@ public abstract class Race implements Runnable {
|
|
|
|
|
* @param boats Takes in an array of boats that are participating in the race.
|
|
|
|
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
|
|
|
|
*/
|
|
|
|
|
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> legs, RaceController controller) {
|
|
|
|
|
this.startingBoats = boats;
|
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
|
|
|
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
|
|
|
|
this.legs = legs;
|
|
|
|
|
this.legs.add(new Leg("Finish"));
|
|
|
|
|
this.controller = controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> marks) {
|
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
|
|
|
|
|
this(boats, marks, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -46,9 +50,10 @@ public abstract class Race implements Runnable {
|
|
|
|
|
System.out.println("Boats Participating:");
|
|
|
|
|
System.out.println("====================");
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " +
|
|
|
|
|
Math.round(startingBoats.get(i).getVelocity()) + "kn");
|
|
|
|
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
|
|
|
|
if (startingBoats.get(i) != null) {
|
|
|
|
|
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " + Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn");
|
|
|
|
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -79,8 +84,10 @@ public abstract class Race implements Runnable {
|
|
|
|
|
System.out.println(minutes + ":" + remainingSeconds);
|
|
|
|
|
|
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
|
updatePosition(boat, SLEEP_TIME);
|
|
|
|
|
checkPosition(boat, totalTimeElapsed);
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
updatePosition(boat, SLEEP_TIME);
|
|
|
|
|
checkPosition(boat, totalTimeElapsed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.updateMap(startingBoats);
|
|
|
|
|
@ -96,7 +103,6 @@ public abstract class Race implements Runnable {
|
|
|
|
|
|
|
|
|
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
|
|
|
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
|
|
|
|
updateController();
|
|
|
|
|
//boat has passed onto new leg
|
|
|
|
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
|
|
|
|
//boat has finished
|
|
|
|
|
@ -116,7 +122,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<BoatInRace> getStartingBoats() {
|
|
|
|
|
public ObservableList<BoatInRace> getStartingBoats() {
|
|
|
|
|
return startingBoats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|