mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed issues caused by merge.
#bug
This commit is contained in:
@@ -7,7 +7,11 @@ import javafx.scene.Parent;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
|
import org.apache.commons.cli.DefaultParser;
|
||||||
|
import org.apache.commons.cli.Options;
|
||||||
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import seng302.model.PolarTable;
|
import seng302.model.PolarTable;
|
||||||
|
|||||||
@@ -4,15 +4,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import seng302.client.ClientPacketParser;
|
import seng302.gameServer.server.messages.BoatActionType;
|
||||||
import seng302.models.Player;
|
import seng302.model.Player;
|
||||||
import seng302.models.Yacht;
|
import seng302.model.Yacht;
|
||||||
import seng302.server.messages.BoatActionType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Static class to hold information about the current state of the game (model)
|
* A Static class to hold information about the current state of the game (model)
|
||||||
@@ -33,8 +27,6 @@ public class GameState implements Runnable {
|
|||||||
private static GameStages currentStage;
|
private static GameStages currentStage;
|
||||||
private static long startTime;
|
private static long startTime;
|
||||||
|
|
||||||
// TODO: 26/07/17 cir27 - Super hackish fix until something more permanent can be made.
|
|
||||||
private static ObservableList<String> observablePlayers = FXCollections.observableArrayList();
|
|
||||||
private static Map<Player, String> playerStringMap = new HashMap<>();
|
private static Map<Player, String> playerStringMap = new HashMap<>();
|
||||||
/*
|
/*
|
||||||
Ideally I would like to make this class an object instantiated by the server and given to
|
Ideally I would like to make this class an object instantiated by the server and given to
|
||||||
@@ -73,20 +65,14 @@ public class GameState implements Runnable {
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObservableList<String> getObservablePlayers () {
|
|
||||||
return observablePlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addPlayer(Player player) {
|
public static void addPlayer(Player player) {
|
||||||
players.add(player);
|
players.add(player);
|
||||||
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName() + " " + player.getYacht().getCountry();
|
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName() + " " + player.getYacht().getCountry();
|
||||||
Platform.runLater(() -> observablePlayers.add(playerText)); //Had to add this to handle javaFX window using array
|
|
||||||
playerStringMap.put(player, playerText);
|
playerStringMap.put(player, playerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlayer(Player player) {
|
public static void removePlayer(Player player) {
|
||||||
players.remove(player);
|
players.remove(player);
|
||||||
observablePlayers.remove(playerStringMap.get(player));
|
|
||||||
playerStringMap.remove(player);
|
playerStringMap.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package seng302.gameServer.server.messages;
|
package seng302.gameServer.server.messages;
|
||||||
|
|
||||||
public class BoatLocationMessage extends Message {
|
public class BoatLocationMessage extends Message {
|
||||||
|
|
||||||
private final int MESSAGE_SIZE = 56;
|
private final int MESSAGE_SIZE = 56;
|
||||||
|
|
||||||
private long messageVersionNumber;
|
private long messageVersionNumber;
|
||||||
@@ -28,6 +29,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the location, altitude and sensor data from the boat.
|
* Describes the location, altitude and sensor data from the boat.
|
||||||
|
*
|
||||||
* @param sourceId ID of the boat
|
* @param sourceId ID of the boat
|
||||||
* @param sequenceNum Sequence number of the message
|
* @param sequenceNum Sequence number of the message
|
||||||
* @param latitude The boats latitude
|
* @param latitude The boats latitude
|
||||||
@@ -35,7 +37,8 @@ public class BoatLocationMessage extends Message {
|
|||||||
* @param heading The boats heading
|
* @param heading The boats heading
|
||||||
* @param boatSpeed The boats speed
|
* @param boatSpeed The boats speed
|
||||||
*/
|
*/
|
||||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude,
|
||||||
|
double heading, long boatSpeed) {
|
||||||
messageVersionNumber = 1;
|
messageVersionNumber = 1;
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
this.sourceId = sourceId;
|
this.sourceId = sourceId;
|
||||||
@@ -94,6 +97,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert binary latitude or longitude to floating point number
|
* Convert binary latitude or longitude to floating point number
|
||||||
|
*
|
||||||
* @param binaryPackedLatLon Binary packed lat OR lon
|
* @param binaryPackedLatLon Binary packed lat OR lon
|
||||||
* @return Floating point lat/lon
|
* @return Floating point lat/lon
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +107,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert binary packed heading to floating point number
|
* Convert binary packed heading to floating point number
|
||||||
|
*
|
||||||
* @param binaryPackedHeading Binary packed heading
|
* @param binaryPackedHeading Binary packed heading
|
||||||
* @return heading as a decimal
|
* @return heading as a decimal
|
||||||
*/
|
*/
|
||||||
@@ -112,6 +117,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert binary packed wind angle to floating point number
|
* Convert binary packed wind angle to floating point number
|
||||||
|
*
|
||||||
* @param binaryPackedWindAngle Binary packed wind angle
|
* @param binaryPackedWindAngle Binary packed wind angle
|
||||||
* @return wind angle as a decimal
|
* @return wind angle as a decimal
|
||||||
*/
|
*/
|
||||||
@@ -121,6 +127,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a latitude or longitude to a binary packed long
|
* Convert a latitude or longitude to a binary packed long
|
||||||
|
*
|
||||||
* @param latLon A floating point latitude/longitude
|
* @param latLon A floating point latitude/longitude
|
||||||
* @return A binary packed lat/lon
|
* @return A binary packed lat/lon
|
||||||
*/
|
*/
|
||||||
@@ -130,6 +137,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a heading to a binary packed long
|
* Convert a heading to a binary packed long
|
||||||
|
*
|
||||||
* @param heading A floating point heading
|
* @param heading A floating point heading
|
||||||
* @return A binary packed heading
|
* @return A binary packed heading
|
||||||
*/
|
*/
|
||||||
@@ -139,6 +147,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a wind angle to a binary packed long
|
* Convert a wind angle to a binary packed long
|
||||||
|
*
|
||||||
* @param windAngle Floating point wind angle
|
* @param windAngle Floating point wind angle
|
||||||
* @return A binary packed wind angle
|
* @return A binary packed wind angle
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,159 +0,0 @@
|
|||||||
package seng302.server.simulator;
|
|
||||||
|
|
||||||
import seng302.server.simulator.mark.Corner;
|
|
||||||
import seng302.server.simulator.mark.Mark;
|
|
||||||
import seng302.server.simulator.parsers.RaceParser;
|
|
||||||
import seng302.utilities.GeoPoint;
|
|
||||||
import seng302.utilities.GeoUtility;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import seng302.model.mark.Mark;
|
|
||||||
import seng302.gameServer.server.simulator.parsers.RaceParser;
|
|
||||||
import seng302.model.GeoPoint;
|
|
||||||
import seng302.utilities.GeoUtility;
|
|
||||||
|
|
||||||
public class Simulator extends Observable implements Runnable {
|
|
||||||
|
|
||||||
private List<Corner> course;
|
|
||||||
private List<Boat> boats;
|
|
||||||
private long lapse;
|
|
||||||
private boolean isRaceStarted;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a simulator instance with given time lapse.
|
|
||||||
* @param lapse time duration in millisecond.
|
|
||||||
*/
|
|
||||||
public Simulator(long lapse) {
|
|
||||||
RaceParser rp = new RaceParser("/server_config/race.xml");
|
|
||||||
course = rp.getCourse();
|
|
||||||
boats = rp.getBoats();
|
|
||||||
this.lapse = lapse;
|
|
||||||
isRaceStarted = false;
|
|
||||||
|
|
||||||
setLegs();
|
|
||||||
|
|
||||||
// set start line's coordinate to boats
|
|
||||||
Double startLat = course.get(0).getCompoundMark().getSubMark(1).getLat();
|
|
||||||
Double startLng = course.get(0).getCompoundMark().getSubMark(1).getLng();
|
|
||||||
for (Boat boat : boats) {
|
|
||||||
boat.setLat(startLat);
|
|
||||||
boat.setLng(startLng);
|
|
||||||
boat.setLastPassedCorner(course.get(0));
|
|
||||||
boat.setHeadingCorner(course.get(1));
|
|
||||||
boat.setSpeed(ThreadLocalRandom.current().nextInt(40000, 60000 + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
int numOfFinishedBoats = 0;
|
|
||||||
|
|
||||||
while (numOfFinishedBoats < boats.size()) {
|
|
||||||
|
|
||||||
// if race has started, then boat should start to move.
|
|
||||||
if (isRaceStarted) {
|
|
||||||
for (Boat boat : boats) {
|
|
||||||
numOfFinishedBoats += moveBoat(boat, lapse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setChanged();
|
|
||||||
notifyObservers(boats);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(lapse);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
System.out.println("[Simulator] interrupted exception ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moves a boat with given time duration.
|
|
||||||
* @param boat the boat to be moved
|
|
||||||
* @param duration the moving duration in milliseconds
|
|
||||||
* @return 1 if the boat has reached the final line, otherwise return 0
|
|
||||||
*/
|
|
||||||
private int moveBoat(Boat boat, double duration) {
|
|
||||||
if (boat.getHeadingCorner() != null) {
|
|
||||||
|
|
||||||
boat.move(boat.getLastPassedCorner().getBearingToNextCorner(), duration);
|
|
||||||
|
|
||||||
GeoPoint boatPos = new GeoPoint(boat.getLat(), boat.getLng());
|
|
||||||
GeoPoint lastMarkPos = boat.getLastPassedCorner().getCompoundMark().getSubMark(1);
|
|
||||||
|
|
||||||
double distanceFromLastMark = GeoUtility.getDistance(boatPos, lastMarkPos);
|
|
||||||
// if a boat passes its heading mark
|
|
||||||
while (distanceFromLastMark >= boat.getLastPassedCorner().getDistanceToNextCorner()) {
|
|
||||||
double compensateDistance = distanceFromLastMark - boat.getLastPassedCorner().getDistanceToNextCorner();
|
|
||||||
boat.setLastPassedCorner(boat.getHeadingCorner());
|
|
||||||
boat.setHeadingCorner(boat.getLastPassedCorner().getNextCorner());
|
|
||||||
|
|
||||||
// heading corner == null means boat has reached the final mark
|
|
||||||
if (boat.getHeadingCorner() == null) {
|
|
||||||
boat.setFinished(true);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// move compensate distance for the mark just passed
|
|
||||||
GeoPoint pos = GeoUtility.getGeoCoordinate(
|
|
||||||
boat.getLastPassedCorner().getCompoundMark().getSubMark(1),
|
|
||||||
boat.getLastPassedCorner().getBearingToNextCorner(),
|
|
||||||
compensateDistance);
|
|
||||||
boat.setLat(pos.getLat());
|
|
||||||
boat.setLng(pos.getLng());
|
|
||||||
distanceFromLastMark = GeoUtility.getDistance(new GeoPoint(boat.getLat(), boat.getLng()),
|
|
||||||
boat.getLastPassedCorner().getCompoundMark().getSubMark(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Link all the corners in the course list so that every corner knows its next
|
|
||||||
* corner, as well as the distance and bearing to its next corner. However,
|
|
||||||
* the last corner's heading is null, which means it is the final line.
|
|
||||||
*/
|
|
||||||
private void setLegs() {
|
|
||||||
// get the bearing from one mark to the next heading mark
|
|
||||||
for (int i = 0; i < course.size() - 1; i++) {
|
|
||||||
|
|
||||||
Mark mark1 = course.get(i).getCompoundMark().getSubMark(1);
|
|
||||||
Mark mark2 = course.get(i + 1).getCompoundMark().getSubMark(1);
|
|
||||||
course.get(i).setDistanceToNextCorner(GeoUtility.getDistance(mark1, mark2));
|
|
||||||
|
|
||||||
course.get(i).setNextCorner(course.get(i + 1));
|
|
||||||
|
|
||||||
course.get(i).setBearingToNextCorner(
|
|
||||||
GeoUtility.getBearing(course.get(i).getCompoundMark().getSubMark(1),
|
|
||||||
course.get(i + 1).getCompoundMark().getSubMark(1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Boat> getBoats(){
|
|
||||||
return boats;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRaceStarted(boolean raceStarted) {
|
|
||||||
isRaceStarted = raceStarted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A list of marks in the race
|
|
||||||
*/
|
|
||||||
public Set<CompoundMark> getMarks(){
|
|
||||||
Set<CompoundMark> marks = new HashSet<>();
|
|
||||||
|
|
||||||
for (Corner c : course){
|
|
||||||
marks.add(c.getCompoundMark());
|
|
||||||
marks.add(c.getCompoundMark());
|
|
||||||
}
|
|
||||||
|
|
||||||
return marks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -86,4 +86,46 @@ public class CompoundMark {
|
|||||||
public List<Mark> getMarks () {
|
public List<Mark> getMarks () {
|
||||||
return marks;
|
return marks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public boolean equals(Object other) {
|
||||||
|
// if (other == null) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!(other instanceof Mark)){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Mark otherMark = (Mark) other;
|
||||||
|
//
|
||||||
|
// if (otherMark.getLat() != getLat() || otherMark.getLongitude() != getLongitude()) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (otherMark.getCompoundMarkID() != getCompoundMarkID()){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (otherMark.getId() != getId()){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!otherMark.getName().equals(name)){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 0;
|
||||||
|
for (Mark mark : marks) {
|
||||||
|
hash += Double.hashCode(mark.getSourceID()) + Double.hashCode(mark.getLat())
|
||||||
|
+ Double.hashCode(mark.getLng()) + mark.getName().hashCode();
|
||||||
|
}
|
||||||
|
return hash + getName().hashCode() + Integer.hashCode(getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-26
@@ -1,28 +1,29 @@
|
|||||||
package seng302.models.mark;
|
package seng302.model.mark;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.models.stream.XMLParser;
|
import seng302.model.stream.xml.generator.Race;
|
||||||
import seng302.models.xml.Race;
|
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||||
import seng302.models.xml.XMLGenerator;
|
import seng302.utilities.XMLGenerator;
|
||||||
import seng302.server.messages.XMLMessageSubType;
|
import seng302.utilities.XMLParser;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to hold the order of the marks in the race.
|
* Class to hold the order of the marks in the race.
|
||||||
*/
|
*/
|
||||||
public class MarkOrder {
|
public class MarkOrder {
|
||||||
private List<Mark> raceMarkOrder;
|
private List<CompoundMark> raceMarkOrder;
|
||||||
private Logger logger = LoggerFactory.getLogger(MarkOrder.class);
|
private Logger logger = LoggerFactory.getLogger(MarkOrder.class);
|
||||||
|
|
||||||
public MarkOrder(){
|
public MarkOrder(){
|
||||||
@@ -33,7 +34,7 @@ public class MarkOrder {
|
|||||||
* @return An ordered list of marks in the race
|
* @return An ordered list of marks in the race
|
||||||
* OR null if the mark order could not be loaded
|
* OR null if the mark order could not be loaded
|
||||||
*/
|
*/
|
||||||
public List<Mark> getMarkOrder(){
|
public List<CompoundMark> getMarkOrder(){
|
||||||
if (raceMarkOrder == null){
|
if (raceMarkOrder == null){
|
||||||
logger.warn("Race order accessed but not instantiated");
|
logger.warn("Race order accessed but not instantiated");
|
||||||
return null;
|
return null;
|
||||||
@@ -48,9 +49,9 @@ public class MarkOrder {
|
|||||||
* @return the next mark
|
* @return the next mark
|
||||||
* OR null if there is no next mark
|
* OR null if there is no next mark
|
||||||
*/
|
*/
|
||||||
public Mark getNextMark(Mark previous){
|
public CompoundMark getNextMark(CompoundMark previous){
|
||||||
for (int i = 0; i < raceMarkOrder.size(); i++){
|
for (int i = 0; i < raceMarkOrder.size(); i++){
|
||||||
Mark mark = raceMarkOrder.get(i);
|
CompoundMark mark = raceMarkOrder.get(i);
|
||||||
|
|
||||||
if (i + 1 >= raceMarkOrder.size()){
|
if (i + 1 >= raceMarkOrder.size()){
|
||||||
return null;
|
return null;
|
||||||
@@ -60,7 +61,6 @@ public class MarkOrder {
|
|||||||
return raceMarkOrder.get(i+1);
|
return raceMarkOrder.get(i+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +69,7 @@ public class MarkOrder {
|
|||||||
* @param xml An AC35 RaceXML
|
* @param xml An AC35 RaceXML
|
||||||
* @return An ordered list of marks in the race
|
* @return An ordered list of marks in the race
|
||||||
*/
|
*/
|
||||||
private List<Mark> loadRaceOrderFromXML(String xml){
|
private List<CompoundMark> loadRaceOrderFromXML(String xml){
|
||||||
XMLParser xmlParser = new XMLParser();
|
|
||||||
XMLParser.RaceXMLObject raceXMLObject;
|
|
||||||
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder db;
|
DocumentBuilder db;
|
||||||
@@ -85,12 +83,13 @@ public class MarkOrder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlParser.constructXML(doc , XMLMessageSubType.RACE.getType());
|
RaceXMLData data = XMLParser.parseRace(doc);
|
||||||
raceXMLObject = xmlParser.getRaceXML();
|
|
||||||
|
|
||||||
if (raceXMLObject != null){
|
if (data != null){
|
||||||
logger.debug("Loaded RaceXML for mark order");
|
logger.debug("Loaded RaceXML for mark order");
|
||||||
return raceXMLObject.getNonDupCompoundMarks();
|
List<CompoundMark> course = new ArrayList<>(data.getCompoundMarks().values());
|
||||||
|
course.sort(Comparator.comparingInt(CompoundMark::getId));
|
||||||
|
return course;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -110,7 +109,6 @@ public class MarkOrder {
|
|||||||
logger.error("Failed to generate raceXML (for race properties)");
|
logger.error("Failed to generate raceXML (for race properties)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
raceMarkOrder = loadRaceOrderFromXML(raceXML);
|
raceMarkOrder = loadRaceOrderFromXML(raceXML);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,7 @@ import java.net.URL;
|
|||||||
import javafx.geometry.Point2D;
|
import javafx.geometry.Point2D;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.net.URL;
|
import seng302.model.GeoPoint;
|
||||||
import java.lang.Math;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CanvasMap retrieves a map image with given geo boundary from Google Map server.
|
* CanvasMap retrieves a map image with given geo boundary from Google Map server.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
|
||||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
|
||||||
</CompoundMark>
|
</CompoundMark>
|
||||||
<CompoundMark CompoundMarkID="11" Name="Mark4">
|
<CompoundMark CompoundMarkID="5" Name="Mark4">
|
||||||
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" />
|
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" />
|
||||||
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
|
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
|
||||||
</CompoundMark>
|
</CompoundMark>
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.models.mark.Mark;
|
import seng302.model.mark.CompoundMark;
|
||||||
import seng302.models.mark.MarkOrder;
|
import seng302.model.mark.MarkOrder;
|
||||||
import seng302.models.mark.SingleMark;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.*;
|
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
|
|
||||||
public class MarkOrderTest {
|
public class MarkOrderTest {
|
||||||
private static MarkOrder markOrder;
|
private static MarkOrder markOrder;
|
||||||
@@ -26,27 +25,27 @@ public class MarkOrderTest {
|
|||||||
assertTrue(markOrder != null);
|
assertTrue(markOrder != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Test if .equals() method on returns true on two marks that are equal
|
// * Test if .equals() method on returns true on two marks that are equal
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMarkEqualsTrue(){
|
// public void testMarkEqualsTrue(){
|
||||||
Mark mark1 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
// M mark1 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
||||||
Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
// Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
||||||
|
//
|
||||||
assertEquals(mark1, mark2);
|
// assertEquals(mark1, mark2);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Test if .equals() method on returns false on two marks that are NOT equal
|
// * Test if .equals() method on returns false on two marks that are NOT equal
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMarkNotEquals(){
|
// public void testMarkNotEquals(){
|
||||||
Mark mark1 = new SingleMark("asf", 1.1, 2.2, 2, 2);
|
// Mark mark1 = new SingleMark("asf", 1.1, 2.2, 2, 2);
|
||||||
Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
// Mark mark2 = new SingleMark("asd", 1.1, 2.2, 1, 2);
|
||||||
|
//
|
||||||
assertNotEquals(mark1, mark2);
|
// assertNotEquals(mark1, mark2);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if .getNextMark() returns null if it is called with the final mark in the race
|
* Test if .getNextMark() returns null if it is called with the final mark in the race
|
||||||
@@ -58,7 +57,7 @@ public class MarkOrderTest {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mark lastMark = markOrder.getMarkOrder().get(markOrder.getMarkOrder().size() - 1);
|
CompoundMark lastMark = markOrder.getMarkOrder().get(markOrder.getMarkOrder().size() - 1);
|
||||||
|
|
||||||
assertEquals(null, markOrder.getNextMark(lastMark));
|
assertEquals(null, markOrder.getNextMark(lastMark));
|
||||||
}
|
}
|
||||||
@@ -68,7 +67,7 @@ public class MarkOrderTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNextMarkNotExists(){
|
public void testNextMarkNotExists(){
|
||||||
Mark someMark = new SingleMark("0-0-0-0-0-0-0", 0.0, 0.1, 2, 1);
|
CompoundMark someMark = new CompoundMark(1, "something");
|
||||||
|
|
||||||
assertEquals(null, markOrder.getNextMark(someMark));
|
assertEquals(null, markOrder.getNextMark(someMark));
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ public class MarkOrderTest {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mark firstMark = markOrder.getMarkOrder().get(0);
|
CompoundMark firstMark = markOrder.getMarkOrder().get(0);
|
||||||
|
|
||||||
assertEquals(markOrder.getMarkOrder().get(1), markOrder.getNextMark(firstMark));
|
assertEquals(markOrder.getMarkOrder().get(1), markOrder.getNextMark(firstMark));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user