|
|
|
|
@ -11,7 +11,7 @@ import java.util.*;
|
|
|
|
|
* Created by fwy13 on 3/03/17.
|
|
|
|
|
*/
|
|
|
|
|
public abstract class Race implements Runnable {
|
|
|
|
|
protected BoatInRace[] startingBoats;
|
|
|
|
|
protected ArrayList<BoatInRace> startingBoats;
|
|
|
|
|
protected ArrayList<Leg> legs;
|
|
|
|
|
protected RaceController controller;
|
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
|
@ -24,14 +24,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(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
|
|
|
|
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> legs, RaceController controller) {
|
|
|
|
|
this.startingBoats = boats;
|
|
|
|
|
this.legs = legs;
|
|
|
|
|
this.legs.add(new Leg("Finish"));
|
|
|
|
|
this.controller = controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
|
|
|
|
|
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> marks) {
|
|
|
|
|
this(boats, marks, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -45,9 +45,10 @@ public abstract class Race implements Runnable {
|
|
|
|
|
//show the boats participating.
|
|
|
|
|
System.out.println("Boats Participating:");
|
|
|
|
|
System.out.println("====================");
|
|
|
|
|
for (int i = 0; i < startingBoats.length; i++) {
|
|
|
|
|
System.out.println(i + 1 + ". " + startingBoats[i].getName() + ", Speed: " + Math.round(startingBoats[i].getVelocity() * 1.94384) + "kn");
|
|
|
|
|
startingBoats[i].setCurrentLeg(legs.get(0));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -68,7 +69,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (boatsFinished < startingBoats.length) {
|
|
|
|
|
while (boatsFinished < startingBoats.size()) {
|
|
|
|
|
timeLoopStarted = System.currentTimeMillis();
|
|
|
|
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
|
long currentTime = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
|
@ -115,7 +116,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BoatInRace[] getStartingBoats() {
|
|
|
|
|
public ArrayList<BoatInRace> getStartingBoats() {
|
|
|
|
|
return startingBoats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|