Fixed DNF position handling
- DNF position is now "-" - If boat DNFs during leg, other boats' rankings are updated to remain accurate #story[15]
This commit is contained in:
@@ -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() {
|
public boolean isFinished() {
|
||||||
return this.finished;
|
return this.finished;
|
||||||
@@ -248,7 +248,7 @@ public class BoatInRace extends Boat {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(int position) {
|
public void setPosition(String position) {
|
||||||
this.position.set(Integer.toString(position + 1));
|
this.position.set(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
private boolean doNotFinish() {
|
private boolean doNotFinish() {
|
||||||
Random rand = new Random();
|
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());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||||
}
|
}
|
||||||
//Update the boat display table in the GUI to reflect the leg change
|
//Update the boat display table in the GUI to reflect the leg change
|
||||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
updatePositions();
|
||||||
boat.setPosition(startingBoats.indexOf(boat));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user