diff --git a/pom.xml b/pom.xml index a562d1a3..524b4562 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,12 @@ json-simple 1.1.1 + + org.mockito + mockito-core + 2.7.13 + test + diff --git a/src/main/java/seng302/controllers/BoatPositionController.java b/src/main/java/seng302/controllers/BoatPositionController.java new file mode 100644 index 00000000..4a82e28a --- /dev/null +++ b/src/main/java/seng302/controllers/BoatPositionController.java @@ -0,0 +1,49 @@ +package seng302.controllers; + +import javafx.fxml.FXML; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; +import seng302.models.Boat; +import seng302.models.Event; + +import java.util.*; + +/** + * Created by ptg19 on 23/03/17. + */ +public class BoatPositionController { + @FXML + private VBox positionVbox; + + private ArrayList boatOrder = new ArrayList<>(); + + public void initialize() { + } + + public void handleEvent(Event event){ + Boat boat = event.getBoat(); + boatOrder.remove(boat); + boat.setMarkLastPast(event.getMarkPosInRace()); + boatOrder.add(boat); + boatOrder.sort(new Comparator() { + @Override + public int compare(Boat b1, Boat b2) { + return b2.getMarkLastPast() - b1.getMarkLastPast(); + } + }); + displayBoats(); + } + + private void displayBoats(){ + positionVbox.getChildren().clear(); + positionVbox.getChildren().removeAll(); + + for (Boat boat: boatOrder){ + positionVbox.getChildren().add(new Text(boat.getTeamName() + " " + boat.getVelocity())); + } + } + + public ArrayList getBoatOrder() { + return boatOrder; + } +} diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 27241d4a..63126939 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -53,6 +53,9 @@ public class CanvasController { @FXML Pane raceTimer; + @FXML + BoatPositionController teamPositionsController; + private Animation.Status raceStatus = Animation.Status.PAUSED; private final int SCALE = 16000; @@ -145,6 +148,11 @@ public class CanvasController { gc.clearRect(0, 0, 19200, 10800); drawCourse(); drawBoats(); + gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight()); + gc.setFill(Color.SKYBLUE); + gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight()); + drawCourse(); + drawBoats(); // If race has started, draw the boats and play the timeline if (race.getRaceTime() > 1){ @@ -162,10 +170,8 @@ public class CanvasController { } }; - generateTimeline(); - + generateTimelines(); timer.start(); - loadTimerView(); Double maxDuration = 0.0; @@ -174,8 +180,6 @@ public class CanvasController { for (TimelineInfo timelineInfo : timelineInfos.values()) { Timeline timeline = timelineInfo.getTimeline(); - System.out.println(); - if (timeline.getTotalDuration().toMillis() >= maxDuration) { maxDuration = timeline.getTotalDuration().toMillis(); maxTimeline = timeline; @@ -201,7 +205,7 @@ public class CanvasController { /** * Generates time line for each boat, and stores time time into timelineInfos hash map */ - private void generateTimeline() { + private void generateTimelines() { HashMap boat_events = race.getEvents(); for (Boat boat : boat_events.keySet()) { @@ -211,12 +215,13 @@ public class CanvasController { List keyFrames = new ArrayList<>(); List events = boat_events.get(boat); + // iterates all events and convert each event to keyFrame, then add them into a list for (Event event : events) { if (event.getIsFinishingEvent()) { keyFrames.add( new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), - event1 -> race.setBoatFinished(boat), + onFinished -> {race.setBoatFinished(boat); teamPositionsController.handleEvent(event);}, new KeyValue(x, event.getThisMark().getLatitude()), new KeyValue(y, event.getThisMark().getLongitude()) ) @@ -224,6 +229,7 @@ public class CanvasController { } else { keyFrames.add( new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), + onFinished -> teamPositionsController.handleEvent(event), new KeyValue(x, event.getThisMark().getLatitude()), new KeyValue(y, event.getThisMark().getLongitude()) ) diff --git a/src/main/java/seng302/models/Boat.java b/src/main/java/seng302/models/Boat.java index 8aaa4e7f..0403f76d 100644 --- a/src/main/java/seng302/models/Boat.java +++ b/src/main/java/seng302/models/Boat.java @@ -13,6 +13,7 @@ public class Boat { private double lon; // - private double distanceToNextMark; private Color color; + private int markLastPast; public Boat(String teamName) { this.teamName = teamName; @@ -101,4 +102,12 @@ public class Boat { public double getSpeedInKnots(){ return Math.round((this.velocity * 1.94384) * 100d) / 100d; } + + public void setMarkLastPast(int markLastPast) { + this.markLastPast = markLastPast; + } + + public int getMarkLastPast() { + return markLastPast; + } } \ No newline at end of file diff --git a/src/main/java/seng302/models/Event.java b/src/main/java/seng302/models/Event.java index 00a2b8bd..5f4dde72 100644 --- a/src/main/java/seng302/models/Event.java +++ b/src/main/java/seng302/models/Event.java @@ -15,6 +15,7 @@ public class Event { private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race private Mark mark1; // This mark private Mark mark2; // Next mark + private int markPosInRace; // the position of the current mark in the race course /** @@ -24,12 +25,12 @@ public class Event { * @param eventTime, what time the event happens * @param eventBoat, the boat that the event belongs to */ - public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2) { + public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2, int markPosInRace) { this.time = eventTime; this.boat = eventBoat; - //this.leg = eventLeg; this.mark1 = mark1; this.mark2 = mark2; + this.markPosInRace = markPosInRace; } /** @@ -39,27 +40,18 @@ public class Event { * @param eventTime, what time the event happens * @param eventBoat, the boat that the event belongs to */ - public Event(Double eventTime, Boat eventBoat, Mark mark1) { + public Event(Double eventTime, Boat eventBoat, Mark mark1, int markPosInRace) { this.time = eventTime; this.boat = eventBoat; this.mark1 = mark1; + this.markPosInRace = markPosInRace; this.isFinishingEvent = true; } - /** - * Gets the time for the event - * - * @return the time for event in millisecond - */ public double getTime() { return this.time; } - /** - * Sets the time for the event - * - * @param eventTime the time for event in millisecond - */ public void setTime(double eventTime) { this.time = eventTime; } @@ -73,28 +65,14 @@ public class Event { return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue())); } - /** - * Gets the involved boat - * - * @return the boat involved in the event - */ public Boat getBoat() { return this.boat; } - /** - * Sets the involved boat - * - * @param eventBoat the involved boat - */ public void setBoat(Boat eventBoat) { this.boat = eventBoat; } - - /** - * Returns true if this event is the boat finishing the race - */ public boolean getIsFinishingEvent() { return this.isFinishingEvent; } @@ -141,21 +119,11 @@ public class Event { return bearing * 180 / Math.PI; } - /** - * Get the mark the event happened on - * - * @return the mark - */ public Mark getThisMark() { return this.mark1; } - /** - * Get the next mark - * - * @return the next mark - */ - public Mark getNextMark() { - return this.mark2; + public int getMarkPosInRace() { + return markPosInRace; } } \ No newline at end of file diff --git a/src/main/java/seng302/models/Race.java b/src/main/java/seng302/models/Race.java index 884be6b9..9c21cc0b 100644 --- a/src/main/java/seng302/models/Race.java +++ b/src/main/java/seng302/models/Race.java @@ -92,7 +92,7 @@ public class Race { // If there are singleMarks after this event if (i < numberOfMarks - 1) { - Event event = new Event(time, boat, course.get(i), course.get(i + 1)); + Event event = new Event(time, boat, course.get(i), course.get(i + 1), i); try { events.get(boat).add(event); @@ -106,7 +106,7 @@ public class Race { // There are no more marks after this event else{ - Event event = new Event(time, boat, course.get(i)); + Event event = new Event(time, boat, course.get(i), i); events.get(boat).add(event); } } diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml index 29165d5d..9534d08d 100644 --- a/src/main/resources/RaceView.fxml +++ b/src/main/resources/RaceView.fxml @@ -9,45 +9,53 @@ - - - - - - - - - - + - + + + + + + + + + + - + + +