Gave BoatInRace a track property that stores the coordinates of the track. Added a method in ResizableRaceCanvas that draws the points on the track every time the canvas updates. [Story 25]
This commit is contained in:
@@ -9,6 +9,8 @@ import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
* Boat in the Race extends Boat.
|
||||
@@ -26,6 +28,10 @@ public class BoatInRace extends Boat {
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
private Queue<GPSCoordinate> track = new ConcurrentLinkedQueue<GPSCoordinate>();
|
||||
private long nextValidTime = 0;
|
||||
private final int TRACK_POINT_TIME_INTERVAL = 1000; // every 2 seconds
|
||||
private final int TRACK_POINT_LIMIT = 10;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -250,4 +256,20 @@ public class BoatInRace extends Boat {
|
||||
public void setPosition(int position) {
|
||||
this.position.set(Integer.toString(position + 1));
|
||||
}
|
||||
|
||||
public boolean addTrackPoint(GPSCoordinate coordinate) {
|
||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||
if (added && this.started && !this.finished) {
|
||||
nextValidTime = System.currentTimeMillis() + TRACK_POINT_TIME_INTERVAL;
|
||||
track.add(coordinate);
|
||||
if (track.size() > TRACK_POINT_LIMIT) {
|
||||
track.remove();
|
||||
}
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
public Queue<GPSCoordinate> getTrack() {
|
||||
return track;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,6 +281,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
} else {
|
||||
displayBoat(boat, 0);
|
||||
}
|
||||
addTrackPoint(boat);
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
@@ -288,6 +289,17 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
private void addTrackPoint(BoatInRace boat) {
|
||||
if (boat.addTrackPoint(boat.getCurrentPosition())) {
|
||||
GraphCoordinate coordinate = this.map.convertGPS(boat.getCurrentPosition());
|
||||
}
|
||||
for (GPSCoordinate coordinate : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(coordinate);
|
||||
gc.setFill(boat.getColour());
|
||||
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRaceBoundaries(ArrayList<GPSCoordinate> boundaries) {
|
||||
this.raceBoundaries = new ArrayList<>();
|
||||
for (GPSCoordinate bound : boundaries) {
|
||||
|
||||
Reference in New Issue
Block a user