mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
added a markpos value to event for use in displaying the team positions #story[426]
This commit is contained in:
@@ -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 Pane raceTimer;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
BoatPositionController teamPositionsController;
|
||||||
|
|
||||||
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +138,7 @@ public class CanvasController {
|
|||||||
AnimationTimer timer = new AnimationTimer() {
|
AnimationTimer timer = new AnimationTimer() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
gc.clearRect(0, 0, 760, 360);
|
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
|
||||||
gc.setFill(Color.SKYBLUE);
|
gc.setFill(Color.SKYBLUE);
|
||||||
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||||
drawCourse();
|
drawCourse();
|
||||||
@@ -205,7 +208,7 @@ public class CanvasController {
|
|||||||
if (event.getIsFinishingEvent()) {
|
if (event.getIsFinishingEvent()) {
|
||||||
keyFrames.add(
|
keyFrames.add(
|
||||||
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
|
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(x, event.getThisMark().getLatitude()),
|
||||||
new KeyValue(y, event.getThisMark().getLongitude())
|
new KeyValue(y, event.getThisMark().getLongitude())
|
||||||
)
|
)
|
||||||
@@ -213,6 +216,7 @@ public class CanvasController {
|
|||||||
} else {
|
} else {
|
||||||
keyFrames.add(
|
keyFrames.add(
|
||||||
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
|
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
|
||||||
|
onFinished -> teamPositionsController.handleEvent(event),
|
||||||
new KeyValue(x, event.getThisMark().getLatitude()),
|
new KeyValue(x, event.getThisMark().getLatitude()),
|
||||||
new KeyValue(y, event.getThisMark().getLongitude())
|
new KeyValue(y, event.getThisMark().getLongitude())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public class Boat {
|
|||||||
private double lon; // -
|
private double lon; // -
|
||||||
private double distanceToNextMark;
|
private double distanceToNextMark;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
private int markLastPast;
|
||||||
|
|
||||||
public Boat(String teamName) {
|
public Boat(String teamName) {
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
@@ -97,4 +98,12 @@ public class Boat {
|
|||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMarkLastPast(int markLastPast) {
|
||||||
|
this.markLastPast = markLastPast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMarkLastPast() {
|
||||||
|
return markLastPast;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ public class Event {
|
|||||||
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
||||||
private Mark mark1; // This mark
|
private Mark mark1; // This mark
|
||||||
private Mark mark2; // Next 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 eventTime, what time the event happens
|
||||||
* @param eventBoat, the boat that the event belongs to
|
* @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.time = eventTime;
|
||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
//this.leg = eventLeg;
|
|
||||||
this.mark1 = mark1;
|
this.mark1 = mark1;
|
||||||
this.mark2 = mark2;
|
this.mark2 = mark2;
|
||||||
|
this.markPosInRace = markPosInRace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,27 +40,18 @@ public class Event {
|
|||||||
* @param eventTime, what time the event happens
|
* @param eventTime, what time the event happens
|
||||||
* @param eventBoat, the boat that the event belongs to
|
* @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.time = eventTime;
|
||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
this.mark1 = mark1;
|
this.mark1 = mark1;
|
||||||
|
this.markPosInRace = markPosInRace;
|
||||||
this.isFinishingEvent = true;
|
this.isFinishingEvent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the time for the event
|
|
||||||
*
|
|
||||||
* @return the time for event in millisecond
|
|
||||||
*/
|
|
||||||
public double getTime() {
|
public double getTime() {
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the time for the event
|
|
||||||
*
|
|
||||||
* @param eventTime the time for event in millisecond
|
|
||||||
*/
|
|
||||||
public void setTime(double eventTime) {
|
public void setTime(double eventTime) {
|
||||||
this.time = eventTime;
|
this.time = eventTime;
|
||||||
}
|
}
|
||||||
@@ -73,28 +65,14 @@ public class Event {
|
|||||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue()));
|
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() {
|
public Boat getBoat() {
|
||||||
return this.boat;
|
return this.boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the involved boat
|
|
||||||
*
|
|
||||||
* @param eventBoat the involved boat
|
|
||||||
*/
|
|
||||||
public void setBoat(Boat eventBoat) {
|
public void setBoat(Boat eventBoat) {
|
||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this event is the boat finishing the race
|
|
||||||
*/
|
|
||||||
public boolean getIsFinishingEvent() {
|
public boolean getIsFinishingEvent() {
|
||||||
return this.isFinishingEvent;
|
return this.isFinishingEvent;
|
||||||
}
|
}
|
||||||
@@ -141,21 +119,11 @@ public class Event {
|
|||||||
return bearing * 180 / Math.PI;
|
return bearing * 180 / Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the mark the event happened on
|
|
||||||
*
|
|
||||||
* @return the mark
|
|
||||||
*/
|
|
||||||
public Mark getThisMark() {
|
public Mark getThisMark() {
|
||||||
return this.mark1;
|
return this.mark1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public int getMarkPosInRace() {
|
||||||
* Get the next mark
|
return markPosInRace;
|
||||||
*
|
|
||||||
* @return the next mark
|
|
||||||
*/
|
|
||||||
public Mark getNextMark() {
|
|
||||||
return this.mark2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ public class Race {
|
|||||||
|
|
||||||
// If there are singleMarks after this event
|
// If there are singleMarks after this event
|
||||||
if (i < numberOfMarks - 1) {
|
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 {
|
try {
|
||||||
events.get(boat).add(event);
|
events.get(boat).add(event);
|
||||||
@@ -106,7 +106,7 @@ public class Race {
|
|||||||
// There are no more marks after this event
|
// There are no more marks after this event
|
||||||
|
|
||||||
else{
|
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);
|
events.get(boat).add(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ public class EventTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getTimeString() throws Exception {
|
public void getTimeString() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
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());
|
assertEquals("20:31:242", event.getTimeString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBoatHeading() throws Exception {
|
public void testBoatHeading() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
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);
|
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ public class EventTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDistanceBetweenMarks() throws Exception {
|
public void testDistanceBetweenMarks() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
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);
|
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user