Fixed finish order
- Added test to check order is determined by velocity - Modified Race class to allow for unit testing #story[15]
This commit is contained in:
@@ -34,8 +34,9 @@ public class Leg {
|
||||
* Construction Method
|
||||
* @param name Name of the Leg
|
||||
*/
|
||||
public Leg(String name) {
|
||||
public Leg(String name, int number) {
|
||||
this.name = name;
|
||||
this.legNumber = number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
private int SLEEP_TIME = 50; //time in milliseconds to pause in a paced loop
|
||||
private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
|
||||
private boolean timerEnabled = true;
|
||||
|
||||
/**
|
||||
* Initailiser for Race
|
||||
@@ -35,7 +36,7 @@ public abstract class Race implements Runnable {
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish"));
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@@ -54,10 +55,14 @@ public abstract class Race implements Runnable {
|
||||
public void run() {
|
||||
setControllerListeners();
|
||||
preRace();
|
||||
countdownTimer();
|
||||
if(timerEnabled) countdownTimer();
|
||||
simulateRace();
|
||||
}
|
||||
|
||||
public void disableTimer() {
|
||||
timerEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the state in waiting for the race starts.
|
||||
*/
|
||||
@@ -146,8 +151,8 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
controller.updateMap(startingBoats);
|
||||
updateTime(calcTimer());
|
||||
if(controller != null) controller.updateMap(startingBoats);
|
||||
if(timerEnabled) updateTime(calcTimer());
|
||||
try {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
||||
|
||||
Reference in New Issue
Block a user