mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Renamed course parser to race parser
- because in AC35 spec. race xml file contain course set up and all other general race settings #story[828]
This commit is contained in:
@@ -0,0 +1,110 @@
|
|||||||
|
package seng302.server.simulator;
|
||||||
|
|
||||||
|
import seng302.server.simulator.mark.Corner;
|
||||||
|
import seng302.server.simulator.mark.Position;
|
||||||
|
|
||||||
|
public class Boat {
|
||||||
|
|
||||||
|
private int sourceID;
|
||||||
|
private double lat;
|
||||||
|
private double lng;
|
||||||
|
private double speed; // in mm/sec
|
||||||
|
private String boatName, shortName, shorterName;
|
||||||
|
|
||||||
|
// haven't been used so far
|
||||||
|
private Corner lastPassedCorner, headingCorner;
|
||||||
|
|
||||||
|
public Boat(int sourceID, String boatName) {
|
||||||
|
this.sourceID = sourceID;
|
||||||
|
this.boatName = boatName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves boat to the heading direction for a given time duration
|
||||||
|
* @param heading moving direction in degree.
|
||||||
|
* @param duration moving duration in millisecond.
|
||||||
|
*/
|
||||||
|
public void move(double heading, double duration) {
|
||||||
|
Double distance = speed * duration / 1000000; // convert mm to meter
|
||||||
|
Position originPos = new Position(lat, lng);
|
||||||
|
Position newPos = GeoUtility.getGeoCoordinate(originPos, heading, distance);
|
||||||
|
this.lat = newPos.getLat();
|
||||||
|
this.lng = newPos.getLng();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.format("Boat (%d): lat: %f, lng: %f", sourceID, lat, lng);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSourceID() {
|
||||||
|
return sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceID(int sourceID) {
|
||||||
|
this.sourceID = sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLat(double lat) {
|
||||||
|
this.lat = lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLng() {
|
||||||
|
return lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLng(double lng) {
|
||||||
|
this.lng = lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(double speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBoatName() {
|
||||||
|
return boatName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoatName(String boatName) {
|
||||||
|
this.boatName = boatName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShortName() {
|
||||||
|
return shortName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShortName(String shortName) {
|
||||||
|
this.shortName = shortName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShorterName() {
|
||||||
|
return shorterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShorterName(String shorterName) {
|
||||||
|
this.shorterName = shorterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Corner getLastPassedCorner() {
|
||||||
|
return lastPassedCorner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastPassedCorner(Corner lastPassedCorner) {
|
||||||
|
this.lastPassedCorner = lastPassedCorner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Corner getHeadingCorner() {
|
||||||
|
return headingCorner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeadingCorner(Corner headingCorner) {
|
||||||
|
this.headingCorner = headingCorner;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package seng302.server.simulator.parsers;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the race xml file to get course details
|
||||||
|
* Created by Haoming Yin (hyi25) on 16/3/2017
|
||||||
|
*/
|
||||||
|
public class BoatsParser extends FileParser {
|
||||||
|
|
||||||
|
private Document doc;
|
||||||
|
|
||||||
|
public BoatsParser(String path) {
|
||||||
|
super(path);
|
||||||
|
this.doc = this.parseFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package seng302.server.simulator.parsers;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import seng302.server.simulator.Boat;
|
||||||
|
import seng302.server.simulator.mark.Corner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the race xml file to get course details
|
||||||
|
* Created by Haoming Yin (hyi25) on 16/3/2017
|
||||||
|
*/
|
||||||
|
public class RaceParser extends FileParser {
|
||||||
|
|
||||||
|
private Document doc;
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
public RaceParser(String path) {
|
||||||
|
super(path);
|
||||||
|
this.path = path;
|
||||||
|
this.doc = this.parseFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Corner> getCourse() {
|
||||||
|
CourseParser cp = new CourseParser(path);
|
||||||
|
return cp.getCourse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Boat> getBoats() {
|
||||||
|
NodeList yachts = doc.getDocumentElement().getElementsByTagName("Yacht");
|
||||||
|
List<Boat> boats = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < yachts.getLength(); i++) {
|
||||||
|
boats.add(getBoat(yachts.item(i)));
|
||||||
|
}
|
||||||
|
return boats;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boat getBoat(Node node) {
|
||||||
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
Element e = (Element) node;
|
||||||
|
|
||||||
|
Integer sourceId = Integer.valueOf(e.getAttribute("SourceID"));
|
||||||
|
return new Boat(sourceId, "Test Boat");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user