Added method to check if a boat is finished the race or not.

- updated server if all boats finish the race, then start sending race finished message.
- race simulator will terminate if all boats finish the race, and prints log.

#story[715]
This commit is contained in:
Haoming Yin
2017-05-03 22:44:25 +12:00
parent d992422efd
commit ed8781b382
3 changed files with 42 additions and 21 deletions
@@ -10,12 +10,14 @@ public class Boat {
private double lng;
private double speed; // in mm/sec
private String boatName, shortName, shorterName;
private boolean isFinished;
private Corner lastPassedCorner, headingCorner;
public Boat(int sourceID, String boatName) {
this.sourceID = sourceID;
this.boatName = boatName;
this.isFinished = false;
}
/**
@@ -106,4 +108,12 @@ public class Boat {
public void setHeadingCorner(Corner headingCorner) {
this.headingCorner = headingCorner;
}
public boolean isFinished() {
return isFinished;
}
public void setFinished(boolean finished) {
isFinished = finished;
}
}
@@ -65,6 +65,8 @@ public class Simulator extends Observable implements Runnable {
e.printStackTrace();
}
}
System.out.println("[SERVER] Race simulator has been terminated");
}
/**
@@ -89,7 +91,10 @@ public class Simulator extends Observable implements Runnable {
boat.setHeadingCorner(boat.getLastPassedCorner().getNextCorner());
// heading corner == null means boat has reached the final mark
if (boat.getHeadingCorner() == null) return 1;
if (boat.getHeadingCorner() == null) {
boat.setFinished(true);
return 1;
}
// move compensate distance for the mark just passed
Position pos = GeoUtility.getGeoCoordinate(