added a markpos value to event for use in displaying the team positions #story[426]

This commit is contained in:
Peter
2017-03-23 21:19:39 +13:00
parent 8578bc4a5b
commit bb8c681270
6 changed files with 61 additions and 46 deletions
@@ -0,0 +1,34 @@
package seng302.controllers;
import javafx.fxml.FXML;
import javafx.scene.layout.VBox;
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<Boat> 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<Boat>() {
@Override
public int compare(Boat b1, Boat b2) {
return b2.getMarkLastPast() - b1.getMarkLastPast();
}
});
}
}
@@ -51,6 +51,9 @@ public class CanvasController {
@FXML Pane raceTimer;
@FXML
BoatPositionController teamPositionsController;
private Animation.Status raceStatus = Animation.Status.PAUSED;
/**
@@ -135,7 +138,7 @@ public class CanvasController {
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
gc.clearRect(0, 0, 760, 360);
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
drawCourse();
@@ -205,7 +208,7 @@ public class CanvasController {
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())
)
@@ -213,6 +216,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())
)
+9
View File
@@ -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;
@@ -97,4 +98,12 @@ public class Boat {
public Color getColor() {
return color;
}
public void setMarkLastPast(int markLastPast) {
this.markLastPast = markLastPast;
}
public int getMarkLastPast() {
return markLastPast;
}
}
+7 -39
View File
@@ -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;
}
}
+2 -2
View File
@@ -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);
}
}
+3 -3
View File
@@ -16,14 +16,14 @@ public class EventTest {
@Test
public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"));
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"), 0);
assertEquals("20:31:242", event.getTimeString());
}
@Test
public void testBoatHeading() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
}
@@ -31,7 +31,7 @@ public class EventTest {
@Test
public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
}