Changed it so Boat can be used as a superclass for StreamedBoat and BoatInRace properly and removed ConstantVelocityRace. Everything that used to use BoatInRace or StreamedBoat now uses it superclass (boat). #pair[jjg64, cbt24] #refactor #story[782]
This commit is contained in:
@@ -21,12 +21,13 @@ import java.util.List;
|
||||
public class ResizableRaceCanvas extends Canvas {
|
||||
private GraphicsContext gc;
|
||||
private RaceMap map;
|
||||
private List<BoatInRace> boats;
|
||||
private List<Boat> boats;
|
||||
private boolean raceAnno = true;
|
||||
private boolean annoName = true;
|
||||
private boolean annoAbbrev = true;
|
||||
private boolean annoSpeed = true;
|
||||
private boolean annoPath = true;
|
||||
private List<Color> colours;
|
||||
private List<GPSCoordinate> raceBoundaries;
|
||||
private List<Marker> markers;
|
||||
double[] xpoints = {}, ypoints = {};
|
||||
@@ -46,6 +47,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
|
||||
this.raceBoundaries = raceData.getBoundary();
|
||||
this.markers = raceData.getMarkers();
|
||||
makeColours();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +55,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
*
|
||||
* @param boats in race
|
||||
*/
|
||||
public void setBoats(List<BoatInRace> boats) {
|
||||
public void setBoats(List<Boat> boats) {
|
||||
this.boats = boats;
|
||||
}
|
||||
|
||||
@@ -81,9 +83,9 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d);
|
||||
}
|
||||
|
||||
public void displayBoat(BoatInRace boat, double angle) {
|
||||
public void displayBoat(Boat boat, double angle, Color colour) {
|
||||
GraphCoordinate pos = this.map.convertGPS(boat.getCurrentPosition());
|
||||
Paint paint = boat.getColour();
|
||||
Paint paint = colour;
|
||||
|
||||
double[] x = {pos.getX() - 6, pos.getX(), pos.getX() + 6};
|
||||
double[] y = {pos.getY() + 12, pos.getY() - 12, pos.getY() + 12};
|
||||
@@ -322,27 +324,29 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
* Draws boats while race in progress, when leg heading is set.
|
||||
*/
|
||||
public void updateBoats() {
|
||||
int currentColour = 0;
|
||||
// TODO Remove null when boats are ready
|
||||
boats = null;
|
||||
if (boats != null) {
|
||||
for (BoatInRace boat : boats) {
|
||||
for (Boat boat : boats) {
|
||||
boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF");
|
||||
boolean isStart = boat.isStarted();
|
||||
if (!finished && isStart) {
|
||||
displayBoat(boat, boat.getHeading());
|
||||
displayBoat(boat, boat.getHeading(), colours.get(currentColour));
|
||||
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
|
||||
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
|
||||
displayLine(wakeFrom, wakeTo, boat.getColour());
|
||||
displayLine(wakeFrom, wakeTo, colours.get(currentColour));
|
||||
} else if (!isStart) {
|
||||
displayBoat(boat, boat.getHeading());
|
||||
displayBoat(boat, boat.getHeading(), colours.get(currentColour));
|
||||
} else {
|
||||
displayBoat(boat, 0);
|
||||
displayBoat(boat, 0, colours.get(currentColour));
|
||||
}
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
|
||||
if(boat.isTrackVisible()) drawTrack(boat);
|
||||
drawTrack(boat, colours.get(currentColour));
|
||||
currentColour = (currentColour + 1) % colours.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,11 +356,11 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
* @param boat whose track is displayed
|
||||
* @see seng302.Model.TrackPoint
|
||||
*/
|
||||
private void drawTrack(BoatInRace boat) {
|
||||
private void drawTrack(Boat boat, Color colour) {
|
||||
if (annoPath && raceAnno) {
|
||||
for (TrackPoint point : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
|
||||
Color boatColour = boat.getColour();
|
||||
Color boatColour = colour;
|
||||
gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha()));
|
||||
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
||||
}
|
||||
@@ -381,6 +385,20 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
private void makeColours() {
|
||||
colours = new ArrayList<Color>(Arrays.asList(
|
||||
Color.BLUEVIOLET,
|
||||
Color.BLACK,
|
||||
Color.RED,
|
||||
Color.ORANGE,
|
||||
Color.DARKOLIVEGREEN,
|
||||
Color.LIMEGREEN,
|
||||
Color.PURPLE,
|
||||
Color.DARKGRAY,
|
||||
Color.YELLOW
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Canvas to resizable.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user