Fixed course xml reader. #story[782]

main
Joseph Gardner 9 years ago
parent 18e9234240
commit 32dabdb187

@ -164,8 +164,7 @@ public class StreamedCourseXMLReader extends XMLReader {
* @return value of "compoundMarkID" attribute
*/
private int getCompoundMarkID(Element element) {
//return Integer.parseInt(element.getAttribute("CompoundMarkID"));
return 3;
return Integer.parseInt(element.getAttribute("CompoundMarkID"));
}
/**
@ -184,10 +183,11 @@ public class StreamedCourseXMLReader extends XMLReader {
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
Marker lastMarker = getMarker(getCompoundMarkID((Element)nCorners.item(0)));
String legName = getCompoundMarkName(getCompoundMarkID((Element)nCorners.item(0)));
Element markXML = (Element)nCorners.item(0);
Marker lastMarker = getMarker(getCompoundMarkID(markXML));
String legName = getCompoundMarkName(getCompoundMarkID(markXML));
for(int i = 1; i < nCorners.getLength(); i++) {
Element markXML = (Element)nCorners.item(i);
markXML = (Element)nCorners.item(i);
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
lastMarker = currentMarker;

@ -7,6 +7,9 @@ import seng302.Controllers.RaceController;
import seng302.GPSCoordinate;
import seng302.Model.*;
import seng302.Networking.MessageDecoders.BoatLocationDecoder;
import seng302.Networking.Utils.BoatStatusMessage;
import seng302.Networking.Utils.ByteConverter;
import seng302.Networking.Utils.Enums.BoatStatus;
import seng302.Networking.Utils.BoatLocationMessage;
import seng302.RaceDataSource;
import seng302.VisualiserInput;
@ -51,18 +54,26 @@ public class StreamedRace extends Race {
}
/**
* Checks the position of the boat, this updates the boats current position.
* Checks the position of the boat.
*
* @param boat Boat that the position is to be updated for.
* @param timeElapsed Time that has elapse since the start of the the race.
* @see BoatInRace
*/
protected void checkPosition(Boat boat, long timeElapsed) {
if (boat.getCurrentLeg().getName().toLowerCase().contains("finish")) {
//boat has finished
StreamedCourse raceData = visualiserInput.getCourse();
BoatStatusMessage boatStatusMessage = visualiserInput.getBoatStatus().get(boat.getSourceID());
BoatStatus boatStatus = BoatStatus.valueOf(boatStatusMessage.getBoatStatus());
int legNumber = boatStatusMessage.getLegNumber();
if (boatStatus == BoatStatus.DNF) {
boat.setDnf(true);
} else if (boatStatus == BoatStatus.FINISHED || legNumber > raceData.getLegs().size()) {
boatsFinished++;
boat.setFinished(true);
boat.setTimeFinished(timeElapsed);
boat.setFinished(true);
} else {
boat.setCurrentLeg(raceData.getLegs().get(legNumber));
}
//Update the boat display table in the GUI to reflect the leg change
updatePositions();

@ -41,7 +41,6 @@ public class VisualiserInput implements Runnable
private Map<Integer, BoatStatusMessage> boatStatus;
public VisualiserInput(StreamedCourse course) throws IOException{
public VisualiserInput(Socket socket, StreamedCourse course) throws IOException{
this.connectionSocket = socket;

@ -76,7 +76,9 @@ public class StreamedRaceTest {
"M2",
"Gate"
};
for(int i = 0; i < legs.size(); i++) assertEquals(expectedNames[i], legs.get(i).getName());
for(int i = 0; i < legs.size(); i++) {
assertEquals(expectedNames[i], legs.get(i).getName());
}
}
/**

Loading…
Cancel
Save