mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Reimplemented race position in the race view. Removed Boat class and Yacht class is replaced completely. Race position "-" shows properly on start screen. Removed BoatTest and TeamsParserTest. Fixed estimated time till finish on server.
#story[818]
This commit is contained in:
@@ -57,6 +57,8 @@ public class App extends Application
|
||||
//Change the StreamReceiver in this else block to change the default data source.
|
||||
else{
|
||||
sr = new StreamReceiver("localhost", 8085, "RaceStream");
|
||||
// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
||||
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
|
||||
}
|
||||
|
||||
sr.start();
|
||||
|
||||
@@ -14,10 +14,7 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.BoatGroup;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.RaceObject;
|
||||
import seng302.models.*;
|
||||
import seng302.models.mark.*;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
import seng302.models.parsers.packets.BoatPositionPacket;
|
||||
@@ -326,13 +323,16 @@ public class CanvasController {
|
||||
*/
|
||||
private void drawBoats() {
|
||||
// Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos();
|
||||
List<Boat> boats = raceViewController.getStartingBoats();
|
||||
// List<Boat> boats = raceViewController.getStartingBoats();
|
||||
Map<Integer, Yacht> boats = StreamParser.getBoats();
|
||||
Double startingX = raceObjects.get(0).getLayoutX();
|
||||
Double startingY = raceObjects.get(0).getLayoutY();
|
||||
Group boatAnnotations = new Group();
|
||||
|
||||
for (Boat boat : boats) {
|
||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||
for (Yacht boat : boats.values()) {
|
||||
// for (Boat boat : boats) {
|
||||
boat.setColour(Colors.getColor());
|
||||
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
|
||||
boatGroup.moveTo(startingX, startingY, 0d);
|
||||
//boatGroup.setStage(raceViewController.getStage());
|
||||
raceObjects.add(boatGroup);
|
||||
|
||||
@@ -65,9 +65,7 @@ public class Controller implements Initializable {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
realTime.setText(format.format(System.currentTimeMillis()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,14 +142,14 @@ public class Controller implements Initializable {
|
||||
posCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("position")
|
||||
);
|
||||
if (StreamParser.isRaceStarted()) {
|
||||
data.addAll(StreamParser.getBoatsPos().values());
|
||||
} else {
|
||||
for (Yacht boat : StreamParser.getBoats().values()) {
|
||||
boat.setPosition("-");
|
||||
data.add(boat);
|
||||
}
|
||||
}
|
||||
// if (StreamParser.isRaceStarted()) {
|
||||
data.addAll(StreamParser.getBoatsPos().values());
|
||||
// } else {
|
||||
// for (Yacht boat : StreamParser.getBoats().values()) {
|
||||
// boat.setPosition("-");
|
||||
// data.add(boat);
|
||||
// }
|
||||
// }
|
||||
teamList.refresh();
|
||||
|
||||
// posCol.setSortType(TableColumn.SortType.ASCENDING);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.Race;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.models.parsers.ConfigParser;
|
||||
import seng302.models.parsers.CourseParser;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
import seng302.models.parsers.TeamsParser;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -41,23 +41,24 @@ public class RaceController {
|
||||
Race race = new Race();
|
||||
// StreamParser.xmlObject
|
||||
// Read team names from file
|
||||
TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||
// TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||
|
||||
// Read course from file
|
||||
ConfigParser config = new ConfigParser(configFile);
|
||||
// ConfigParser config = new ConfigParser(configFile);
|
||||
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Boat> teams = tp.getBoats();
|
||||
// ArrayList<Boat> teams = tp.getBoats();
|
||||
Map<Long, Yacht> teams = StreamParser.getBoatsPos();
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = teams.size();
|
||||
|
||||
//get time scale
|
||||
double timeScale = config.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
// double timeScale = config.getTimeScale();
|
||||
// race.setTimeScale(timeScale);
|
||||
|
||||
for (Boat boat : teams) {
|
||||
boatNames.add(boat.getTeamName());
|
||||
for (Yacht boat : teams.values()) {
|
||||
boatNames.add(boat.getBoatName());
|
||||
race.addBoat(boat);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class RaceResultController implements Initializable{
|
||||
int boatPosition = this.race.getFinishedBoats().length;
|
||||
|
||||
for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){
|
||||
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getTeamName()));
|
||||
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getBoatName()));
|
||||
boatPosition--;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
import javafx.animation.Animation;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
@@ -44,11 +45,11 @@ public class RaceViewController extends Thread{
|
||||
@FXML
|
||||
private CanvasController includedCanvasController;
|
||||
|
||||
private ArrayList<Boat> startingBoats = new ArrayList<>();
|
||||
private ArrayList<Yacht> startingBoats = new ArrayList<>();
|
||||
private boolean displayFps;
|
||||
private Timeline timerTimeline;
|
||||
private Map<Boat, TimelineInfo> timelineInfos = new HashMap<>();
|
||||
private ArrayList<Boat> boatOrder = new ArrayList<>();
|
||||
private Map<Yacht, TimelineInfo> timelineInfos = new HashMap<>();
|
||||
private ArrayList<Yacht> boatOrder = new ArrayList<>();
|
||||
private Race race;
|
||||
private Stage stage;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class RaceViewController extends Thread{
|
||||
RaceController raceController = new RaceController();
|
||||
raceController.initializeRace();
|
||||
race = raceController.getRace();
|
||||
for (Boat boat : race.getBoats()) {
|
||||
for (Yacht boat : race.getBoats()) {
|
||||
startingBoats.add(boat);
|
||||
}
|
||||
// try{
|
||||
@@ -72,6 +73,7 @@ public class RaceViewController extends Thread{
|
||||
initializeTimer();
|
||||
initializeSettings();
|
||||
initialiseWindDirection();
|
||||
initialisePositionVBox();
|
||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||
// double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
|
||||
// windDirectionText.setText(String.format("%.1f°", windDirection));
|
||||
@@ -160,12 +162,26 @@ public class RaceViewController extends Thread{
|
||||
windDirTimeline.playFromStart();
|
||||
}
|
||||
|
||||
private void initialisePositionVBox() {
|
||||
|
||||
Timeline posVBoxTimeline = new Timeline();
|
||||
posVBoxTimeline.setCycleCount(Timeline.INDEFINITE);
|
||||
posVBoxTimeline.getKeyFrames().add(
|
||||
new KeyFrame(Duration.seconds(1),
|
||||
event -> {
|
||||
showOrder();
|
||||
})
|
||||
);
|
||||
posVBoxTimeline.playFromStart();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates time line for each boat, and stores time time into timelineInfos hash map
|
||||
*/
|
||||
private void initializeTimelines() {
|
||||
HashMap<Boat, List> boat_events = race.getEvents();
|
||||
for (Boat boat : boat_events.keySet()) {
|
||||
HashMap<Yacht, List> boat_events = race.getEvents();
|
||||
for (Yacht boat : boat_events.keySet()) {
|
||||
startingBoats.add(boat);
|
||||
// // x, y are the real time coordinates
|
||||
// DoubleProperty x = new SimpleDoubleProperty();
|
||||
@@ -271,13 +287,13 @@ public class RaceViewController extends Thread{
|
||||
}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
Boat boat = event.getBoat();
|
||||
Yacht boat = event.getBoat();
|
||||
boatOrder.remove(boat);
|
||||
boat.setMarkLastPast(event.getMarkPosInRace());
|
||||
boatOrder.add(boat);
|
||||
boatOrder.sort(new Comparator<Boat>() {
|
||||
boatOrder.sort(new Comparator<Yacht>() {
|
||||
@Override
|
||||
public int compare(Boat b1, Boat b2) {
|
||||
public int compare(Yacht b1, Yacht b2) {
|
||||
return b2.getMarkLastPast() - b1.getMarkLastPast();
|
||||
}
|
||||
});
|
||||
@@ -288,8 +304,20 @@ public class RaceViewController extends Thread{
|
||||
positionVbox.getChildren().clear();
|
||||
positionVbox.getChildren().removeAll();
|
||||
|
||||
for (Boat boat : boatOrder) {
|
||||
positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
|
||||
// for (Boat boat : boatOrder) {
|
||||
// positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
|
||||
// }
|
||||
|
||||
for (Yacht boat : StreamParser.getBoatsPos().values()) {
|
||||
System.out.println(boat.getBoatStatus());
|
||||
if (boat.getBoatStatus() == 3) { // 3 is finish status
|
||||
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
|
||||
boat.getShortName() + " (Finished)"));
|
||||
} else {
|
||||
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
|
||||
boat.getShortName() + " "));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,11 +369,11 @@ public class RaceViewController extends Thread{
|
||||
return race;
|
||||
}
|
||||
|
||||
public Map<Boat, TimelineInfo> getTimelineInfos() {
|
||||
public Map<Yacht, TimelineInfo> getTimelineInfos() {
|
||||
return timelineInfos;
|
||||
}
|
||||
|
||||
public ArrayList<Boat> getStartingBoats(){
|
||||
public ArrayList<Yacht> getStartingBoats(){
|
||||
return startingBoats;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,147 +1,143 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
import javafx.util.Pair;
|
||||
|
||||
/**
|
||||
* Represents a boat in the race.
|
||||
*/
|
||||
public class Boat {
|
||||
|
||||
private String teamName;
|
||||
private double velocity;
|
||||
private double lat;
|
||||
private double lon;
|
||||
private double heading;
|
||||
private int markLastPast;
|
||||
private String shortName;
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* For testing only.
|
||||
* @param teamName Boat team name.
|
||||
*/
|
||||
public Boat(String teamName) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = 10; // Default velocity
|
||||
this.lat = 0.0;
|
||||
this.lon = 0.0;
|
||||
this.shortName = "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a boat in the race.
|
||||
*
|
||||
* @param teamName The name of the team sailing the boat
|
||||
* @param boatVelocity The speed of the boat in meters/second
|
||||
* @param shortName A shorter version of the teams name
|
||||
*/
|
||||
public Boat(String teamName, double boatVelocity, String shortName, int id) {
|
||||
this.teamName = teamName;
|
||||
this.velocity = boatVelocity;
|
||||
this.shortName = shortName;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the team sailing the boat
|
||||
*
|
||||
* @return The name of the team
|
||||
*/
|
||||
public String getTeamName() {
|
||||
return this.teamName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the team sailing the boat
|
||||
*
|
||||
* @param teamName The name of the team
|
||||
*/
|
||||
public void setTeamName(String teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets velocity of the boat
|
||||
*
|
||||
* @return a float number of the boat velocity
|
||||
*/
|
||||
public double getVelocity() {
|
||||
return this.velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets velocity of the boat
|
||||
*
|
||||
* @param velocity The velocity of boat
|
||||
*/
|
||||
public void setVelocity(double velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boats location
|
||||
*
|
||||
* @param lat, the boats latitude
|
||||
* @param lon, the boats longitude
|
||||
*/
|
||||
public void setLocation(double lat, double lon) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public Pair<Double, Double> getLocation ()
|
||||
{
|
||||
return new Pair<>(this.lat, this.lon);
|
||||
}
|
||||
|
||||
public double getLatitude(){
|
||||
return this.lat;
|
||||
}
|
||||
|
||||
public double getLongitude(){
|
||||
return this.lon;
|
||||
}
|
||||
|
||||
public void setLatitude (double latitude) {
|
||||
this.lat = latitude;
|
||||
}
|
||||
|
||||
public void setlongitude (double longitude) {
|
||||
this.lon =longitude;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public double getHeading(){
|
||||
return this.heading;
|
||||
}
|
||||
|
||||
public void setHeading(double heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
public String getShortName(){
|
||||
return this.shortName;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
//package seng302.models;
|
||||
//
|
||||
//import javafx.geometry.Point2D;
|
||||
//import javafx.scene.paint.Color;
|
||||
//import javafx.scene.shape.Polygon;
|
||||
//import javafx.scene.text.Text;
|
||||
//import javafx.scene.transform.Rotate;
|
||||
//import javafx.scene.transform.Translate;
|
||||
//import javafx.util.Pair;
|
||||
//
|
||||
///**
|
||||
//* Represents a boat in the race.
|
||||
//*/
|
||||
//public class Boat {
|
||||
//
|
||||
// private String teamName;
|
||||
// private double velocity;
|
||||
// private double lat;
|
||||
// private double lon;
|
||||
// private double heading;
|
||||
// private int markLastPast;
|
||||
// private String shortName;
|
||||
// private int id;
|
||||
//
|
||||
// public Boat(String teamName) {
|
||||
// this.teamName = teamName;
|
||||
// this.velocity = 10; // Default velocity
|
||||
// this.lat = 0.0;
|
||||
// this.lon = 0.0;
|
||||
// this.shortName = "";
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Represents a boat in the race.
|
||||
// *
|
||||
// * @param teamName The name of the team sailing the boat
|
||||
// * @param boatVelocity The speed of the boat in meters/second
|
||||
// * @param shortName A shorter version of the teams name
|
||||
// */
|
||||
// public Boat(String teamName, double boatVelocity, String shortName, int id) {
|
||||
// this.teamName = teamName;
|
||||
// this.velocity = boatVelocity;
|
||||
// this.shortName = shortName;
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the name of the team sailing the boat
|
||||
// *
|
||||
// * @return The name of the team
|
||||
// */
|
||||
// public String getTeamName() {
|
||||
// return this.teamName;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the name of the team sailing the boat
|
||||
// *
|
||||
// * @param teamName The name of the team
|
||||
// */
|
||||
// public void setTeamName(String teamName) {
|
||||
// this.teamName = teamName;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets velocity of the boat
|
||||
// *
|
||||
// * @return a float number of the boat velocity
|
||||
// */
|
||||
// public double getVelocity() {
|
||||
// return this.velocity;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets velocity of the boat
|
||||
// *
|
||||
// * @param velocity The velocity of boat
|
||||
// */
|
||||
// public void setVelocity(double velocity) {
|
||||
// this.velocity = velocity;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the boats location
|
||||
// *
|
||||
// * @param lat, the boats latitude
|
||||
// * @param lon, the boats longitude
|
||||
// */
|
||||
// public void setLocation(double lat, double lon) {
|
||||
// this.lat = lat;
|
||||
// this.lon = lon;
|
||||
// }
|
||||
//
|
||||
// public Pair<Double, Double> getLocation ()
|
||||
// {
|
||||
// return new Pair<>(this.lat, this.lon);
|
||||
// }
|
||||
//
|
||||
// public double getLatitude(){
|
||||
// return this.lat;
|
||||
// }
|
||||
//
|
||||
// public double getLongitude(){
|
||||
// return this.lon;
|
||||
// }
|
||||
//
|
||||
// public void setLatitude (double latitude) {
|
||||
// this.lat = latitude;
|
||||
// }
|
||||
//
|
||||
// public void setlongitude (double longitude) {
|
||||
// this.lon =longitude;
|
||||
// }
|
||||
//
|
||||
// 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;
|
||||
// }
|
||||
//
|
||||
// public double getHeading(){
|
||||
// return this.heading;
|
||||
// }
|
||||
//
|
||||
// public void setHeading(double heading) {
|
||||
// this.heading = heading;
|
||||
// }
|
||||
//
|
||||
// public String getShortName(){
|
||||
// return this.shortName;
|
||||
// }
|
||||
//
|
||||
// public int getId() {
|
||||
// return id;
|
||||
// }
|
||||
//}
|
||||
@@ -33,7 +33,7 @@ public class BoatGroup extends RaceObject{
|
||||
private int wakeGenerationDelay = 10;
|
||||
private double distanceTravelled;
|
||||
//Graphical objects
|
||||
private Boat boat;
|
||||
private Yacht boat;
|
||||
private Group lineGroup = new Group();
|
||||
private Polygon boatPoly;
|
||||
private Text teamNameObject;
|
||||
@@ -54,7 +54,7 @@ public class BoatGroup extends RaceObject{
|
||||
* BoatGroup to update.
|
||||
* @param color The colour of the boat polygon and the trailing line.
|
||||
*/
|
||||
public BoatGroup (Boat boat, Color color){
|
||||
public BoatGroup (Yacht boat, Color color){
|
||||
this.boat = boat;
|
||||
initChildren(color);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class BoatGroup extends RaceObject{
|
||||
* @param color The colour of the boat polygon and the trailing line.
|
||||
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon.
|
||||
*/
|
||||
public BoatGroup (Boat boat, Color color, double... points)
|
||||
public BoatGroup (Yacht boat, Color color, double... points)
|
||||
{
|
||||
this.boat = boat;
|
||||
initChildren(color, points);
|
||||
@@ -295,7 +295,7 @@ public class BoatGroup extends RaceObject{
|
||||
wake.setVisible(visible);
|
||||
}
|
||||
|
||||
public Boat getBoat() {
|
||||
public Yacht getBoat() {
|
||||
return boat;
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ public class BoatGroup extends RaceObject{
|
||||
*/
|
||||
public boolean hasRaceId (int... raceIds) {
|
||||
for (int id : raceIds) {
|
||||
if (id == boat.getId())
|
||||
if (id == boat.getSourceID())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -319,7 +319,7 @@ public class BoatGroup extends RaceObject{
|
||||
* @return An array containing all ID's associated with this RaceObject.
|
||||
*/
|
||||
public int[] getRaceIds () {
|
||||
return new int[] {boat.getId()};
|
||||
return new int[] {boat.getSourceID()};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Date;
|
||||
*/
|
||||
public class Event {
|
||||
private Double time; // Time the event occurs
|
||||
private Boat boat;
|
||||
private Yacht boat;
|
||||
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
||||
private Mark mark1; // This mark
|
||||
private Mark mark2; // Next mark
|
||||
@@ -28,7 +28,7 @@ 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, int markPosInRace) {
|
||||
public Event(Double eventTime, Yacht eventBoat, Mark mark1, Mark mark2, int markPosInRace) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.mark1 = mark1;
|
||||
@@ -45,7 +45,7 @@ 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, int markPosInRace) {
|
||||
public Event(Double eventTime, Yacht eventBoat, Mark mark1, int markPosInRace) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.mark1 = mark1;
|
||||
@@ -70,11 +70,11 @@ public class Event {
|
||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue()));
|
||||
}
|
||||
|
||||
public Boat getBoat() {
|
||||
public Yacht getBoat() {
|
||||
return this.boat;
|
||||
}
|
||||
|
||||
public void setBoat(Boat eventBoat) {
|
||||
public void setBoat(Yacht eventBoat) {
|
||||
this.boat = eventBoat;
|
||||
}
|
||||
|
||||
@@ -90,10 +90,10 @@ public class Event {
|
||||
public String getEventString() {
|
||||
// This event is a boat finishing the race
|
||||
if (this.isFinishingEvent) {
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
||||
return (this.getTimeString() + ", " + this.getBoat().getBoatName() + " finished the race");
|
||||
}
|
||||
// System.out.println(this.getDistanceBetweenMarks());
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
|
||||
return (this.getTimeString() + ", " + this.getBoat().getBoatName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.util.*;
|
||||
*/
|
||||
public class Race {
|
||||
|
||||
private ArrayList<Boat> boats; // The boats in the race
|
||||
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
|
||||
private HashMap<Boat, List> events = new HashMap<>(); // The events that occur in the race
|
||||
private ArrayList<Yacht> boats; // The boats in the race
|
||||
private ArrayList<Yacht> finishingOrder; // The order in which the boats finish the race
|
||||
private HashMap<Yacht, List> events = new HashMap<>(); // The events that occur in the race
|
||||
private List<Mark> course; // Marks in the race
|
||||
private long startTime = 0;
|
||||
private double timeScale = 1;
|
||||
@@ -33,7 +33,7 @@ public class Race {
|
||||
*
|
||||
* @param boat, the boat to add
|
||||
*/
|
||||
public void addBoat(Boat boat) {
|
||||
public void addBoat(Yacht boat) {
|
||||
boats.add(boat);
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ public class Race {
|
||||
*
|
||||
* @return a list of boats
|
||||
*/
|
||||
public Boat[] getShuffledBoats() {
|
||||
public Yacht[] getShuffledBoats() {
|
||||
// Shuffle the list of boats
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(this.boats, new Random(seed));
|
||||
|
||||
return boats.toArray(new Boat[boats.size()]);
|
||||
return boats.toArray(new Yacht[boats.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +56,8 @@ public class Race {
|
||||
*
|
||||
* @return a list of boats
|
||||
*/
|
||||
public Boat[] getFinishedBoats() {
|
||||
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]);
|
||||
public Yacht[] getFinishedBoats() {
|
||||
return this.finishingOrder.toArray(new Yacht[this.finishingOrder.size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ public class Race {
|
||||
*
|
||||
* @return a list of the boats competing in the race
|
||||
*/
|
||||
public Boat[] getBoats() {
|
||||
return boats.toArray(new Boat[boats.size()]);
|
||||
public Yacht[] getBoats() {
|
||||
return boats.toArray(new Yacht[boats.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,7 @@ public class Race {
|
||||
*/
|
||||
private void generateEvents() {
|
||||
|
||||
for (Boat boat : this.boats) {
|
||||
for (Yacht boat : this.boats) {
|
||||
double totalDistance = 0;
|
||||
int numberOfMarks = this.course.size();
|
||||
|
||||
@@ -146,7 +146,7 @@ public class Race {
|
||||
* Get a map of the events in the race
|
||||
* @return
|
||||
*/
|
||||
public HashMap<Boat, List> getEvents() {
|
||||
public HashMap<Yacht, List> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public class Race {
|
||||
* Set a boat as finished
|
||||
* @param boat The boat that has finished the race/home/cosc/student/wmu16
|
||||
*/
|
||||
public void setBoatFinished(Boat boat){
|
||||
public void setBoatFinished(Yacht boat){
|
||||
this.finishingOrder.add(boat);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
@@ -10,6 +12,10 @@ import java.text.SimpleDateFormat;
|
||||
* also done outside Boat class because some old variables are not used anymore.
|
||||
*/
|
||||
public class Yacht {
|
||||
private Color colour;
|
||||
private double velocity;
|
||||
private Integer markLastPast;
|
||||
|
||||
private String boatType;
|
||||
private Integer sourceID;
|
||||
private String hullID; //matches HullNum in the XML spec.
|
||||
@@ -25,6 +31,29 @@ public class Yacht {
|
||||
private Long estimateTimeAtFinish;
|
||||
private String position;
|
||||
|
||||
/**
|
||||
* Used in EventTest and RaceTest.
|
||||
*
|
||||
* @param boatName Create a yacht object with name.
|
||||
*/
|
||||
public Yacht (String boatName) {
|
||||
this.boatName = boatName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in BoatGroupTest.
|
||||
*
|
||||
* @param boatName The name of the team sailing the boat
|
||||
* @param boatVelocity The speed of the boat in meters/second
|
||||
* @param shortName A shorter version of the teams name
|
||||
*/
|
||||
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
|
||||
this.boatName = boatName;
|
||||
this.velocity = boatVelocity;
|
||||
this.shortName = shortName;
|
||||
this.sourceID = id;
|
||||
}
|
||||
|
||||
public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) {
|
||||
this.boatType = boatType;
|
||||
this.sourceID = sourceID;
|
||||
@@ -111,4 +140,28 @@ public class Yacht {
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Color getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public void setColour(Color colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public double getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public void setVelocity(double velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Integer getMarkLastPast() {
|
||||
return markLastPast;
|
||||
}
|
||||
|
||||
public void setMarkLastPast(Integer markLastPast) {
|
||||
this.markLastPast = markLastPast;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,10 +231,16 @@ public class StreamParser extends Thread{
|
||||
// boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)));
|
||||
// boatStatuses.add(boatStatus);
|
||||
}
|
||||
int pos = 1;
|
||||
for (Yacht yacht : boatsPos.values()) {
|
||||
yacht.setPosition(String.valueOf(pos));
|
||||
pos++;
|
||||
if (isRaceStarted()) {
|
||||
int pos = 1;
|
||||
for (Yacht yacht : boatsPos.values()) {
|
||||
yacht.setPosition(String.valueOf(pos));
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
for (Yacht yacht : boatsPos.values()) {
|
||||
yacht.setPosition("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
package seng302.models.parsers;
|
||||
|
||||
import org.w3c.dom.*;
|
||||
import seng302.models.Boat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class TeamsParser extends FileParser {
|
||||
|
||||
private Document doc;
|
||||
|
||||
public TeamsParser(String path) {
|
||||
super(path);
|
||||
this.doc = this.parseFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a boat instance by a given team node
|
||||
* @param node a boat node containing name, alias and velocity
|
||||
* @return an instance of Boat
|
||||
*/
|
||||
private Boat parseBoat(Node node) {
|
||||
try {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
String name = element.getElementsByTagName("name").item(0).getTextContent();
|
||||
String alias = element.getElementsByTagName("alias").item(0).getTextContent();
|
||||
double velocity = Double.valueOf(element.getElementsByTagName("velocity").item(0).getTextContent());
|
||||
int id = Integer.valueOf(element.getElementsByTagName("id").item(0).getTextContent());
|
||||
Boat boat = new Boat(name, velocity, alias, id);
|
||||
return boat;
|
||||
} else {
|
||||
throw new NoSuchElementException("Cannot generate a boat by given node");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an arraylist of boats instance.
|
||||
* @return an arraylist of boats in teams file
|
||||
*/
|
||||
public ArrayList<Boat> getBoats() {
|
||||
ArrayList<Boat> boats = new ArrayList<>();
|
||||
|
||||
try {
|
||||
NodeList nodes = this.doc.getElementsByTagName("team");
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
Node node = nodes.item(i);
|
||||
boats.add(parseBoat(node));
|
||||
}
|
||||
return boats;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//package seng302.models.parsers;
|
||||
//
|
||||
//import org.w3c.dom.*;
|
||||
//import seng302.models.Yacht;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.NoSuchElementException;
|
||||
//
|
||||
//public class TeamsParser extends FileParser {
|
||||
//
|
||||
// private Document doc;
|
||||
//
|
||||
// public TeamsParser(String path) {
|
||||
// super(path);
|
||||
// this.doc = this.parseFile();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Create a boat instance by a given team node
|
||||
// * @param node a boat node containing name, alias and velocity
|
||||
// * @return an instance of Boat
|
||||
// */
|
||||
// private Yacht parseBoat(Node node) {
|
||||
// try {
|
||||
// if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
// Element element = (Element) node;
|
||||
// String name = element.getElementsByTagName("name").item(0).getTextContent();
|
||||
// String alias = element.getElementsByTagName("alias").item(0).getTextContent();
|
||||
// double velocity = Double.valueOf(element.getElementsByTagName("velocity").item(0).getTextContent());
|
||||
// int id = Integer.valueOf(element.getElementsByTagName("id").item(0).getTextContent());
|
||||
// Yacht boat = new Yacht(name, velocity, alias, id);
|
||||
// return boat;
|
||||
// } else {
|
||||
// throw new NoSuchElementException("Cannot generate a boat by given node");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Create an arraylist of boats instance.
|
||||
// * @return an arraylist of boats in teams file
|
||||
// */
|
||||
// public ArrayList<Yacht> getBoats() {
|
||||
// ArrayList<Yacht> boats = new ArrayList<>();
|
||||
//
|
||||
// try {
|
||||
// NodeList nodes = this.doc.getElementsByTagName("team");
|
||||
// for (int i = 0; i < nodes.getLength(); i++) {
|
||||
// Node node = nodes.item(i);
|
||||
// boats.add(parseBoat(node));
|
||||
// }
|
||||
// return boats;
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
|
||||
@@ -120,6 +120,6 @@ public class Boat {
|
||||
}
|
||||
|
||||
public long getEstimatedTimeTillFinish(){
|
||||
return (long) (getSpeed()) + System.currentTimeMillis();
|
||||
return (long) (-getSpeed()) + System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user