Boat race finishes when all boats have crossed the line
- Added a boolean flag 'finished' to BoatInRace #implement #story[9]
This commit is contained in:
@@ -17,6 +17,7 @@ public class BoatInRace extends Boat {
|
|||||||
private GPSCoordinate currentPosition;
|
private GPSCoordinate currentPosition;
|
||||||
private long timeFinished;
|
private long timeFinished;
|
||||||
private Color colour;
|
private Color colour;
|
||||||
|
private boolean finished = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -112,6 +113,14 @@ public class BoatInRace extends Boat {
|
|||||||
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFinished() {
|
||||||
|
return this.finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinished(boolean bool) {
|
||||||
|
this.finished = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public abstract class Race implements Runnable {
|
|||||||
System.out.println(minutes + ":" + remainingSeconds);
|
System.out.println(minutes + ":" + remainingSeconds);
|
||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
updatePosition(boat, SLEEP_TIME);
|
updatePosition(boat, SLEEP_TIME);
|
||||||
checkPosition(boat, totalTimeElapsed);
|
checkPosition(boat, totalTimeElapsed);
|
||||||
}
|
}
|
||||||
@@ -123,8 +123,8 @@ public abstract class Race implements Runnable {
|
|||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
//boat has finished
|
//boat has finished
|
||||||
boat.setTimeFinished(timeElapsed);
|
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
|
boat.setFinished(true);
|
||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
if (boats != null) {
|
if (boats != null) {
|
||||||
for (BoatInRace boat : boats) {
|
for (BoatInRace boat : boats) {
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
||||||
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
|
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
|
||||||
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
||||||
System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
//System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
||||||
displayPoint(graphCoordinate, colour);
|
displayPoint(graphCoordinate, colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user