diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index 544eceb0..d306eb4c 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -217,7 +217,7 @@ public class BoatInRace extends Boat { } /** - * @return true if boat has finished, fals eif not + * @return true if boat has finished, false if not */ public boolean isFinished() { return this.finished; @@ -248,7 +248,7 @@ public class BoatInRace extends Boat { return position; } - public void setPosition(int position) { - this.position.set(Integer.toString(position + 1)); + public void setPosition(String position) { + this.position.set(position); } } diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 7afe86b2..4defdeb6 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -174,7 +174,7 @@ public abstract class Race implements Runnable { private boolean doNotFinish() { Random rand = new Random(); - return rand.nextInt(100) < 1; + return rand.nextInt(4) < 1; } /** @@ -262,8 +262,21 @@ public abstract class Race implements Runnable { boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); } //Update the boat display table in the GUI to reflect the leg change - FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber()); - boat.setPosition(startingBoats.indexOf(boat)); + updatePositions(); + } + } + + /** + * Update position of boats in race, no position if on starting leg or DNF. + */ + private void updatePositions() { + FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber()); + for(BoatInRace boat: startingBoats) { + if(boat != null) { + boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1)); + if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0) + boat.setPosition("-"); + } } }