Added the race results to the RaceResultController. Also fixed some bugs

- Fixed a bug where the race results would be out of order.
- Changed the colour of the start and finish gates
- Added the race results to the RaceResultController and updated view

Tags: #fix #implement #story[13, 10, 11]
This commit is contained in:
Michael Rausch
2017-03-22 22:30:49 +13:00
parent a41f2e4bde
commit 9e22eac4d8
8 changed files with 76 additions and 56 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
}, },
{ {
"team-name": "Artemis Racing", "team-name": "Artemis Racing",
"velocity": 10.3 "velocity": 59.3
}, },
{ {
"team-name": "Emirates Team New Zealand", "team-name": "Emirates Team New Zealand",
@@ -17,7 +17,7 @@
}, },
{ {
"team-name": "Groupama Team France", "team-name": "Groupama Team France",
"velocity": 9.9 "velocity": 29.9
}, },
{ {
"team-name": "Land Rover BAR", "team-name": "Land Rover BAR",
+1 -1
View File
@@ -3,6 +3,6 @@
<configurations> <configurations>
<race-name>AC35</race-name> <race-name>AC35</race-name>
<race-size>6</race-size> <race-size>6</race-size>
<time-scale>2.0</time-scale> <time-scale>1.0</time-scale>
</configurations> </configurations>
@@ -40,23 +40,23 @@ public class CanvasController {
private GraphicsContext gc; private GraphicsContext gc;
private HashMap<Boat, TimelineInfo> timelineInfos; private HashMap<Boat, TimelineInfo> timelineInfos;
private AnchorPane raceResults;
private final double ORIGIN_LAT = 32.320504; private final double ORIGIN_LAT = 32.320504;
private final double ORIGIN_LON = -64.857063; private final double ORIGIN_LON = -64.857063;
private final double VIEW_CORNER_LAT = 32.280808;
private final double VIEW_CORNER_LON = -64.858401;
@FXML @FXML
private AnchorPane contentAnchorPane; private AnchorPane contentAnchorPane;
@FXML private void loadRaceResultView() {
private RaceResultController raceResultController; FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml"));
loader.setController(new RaceResultController(race));
private void setContentPane(String jfxUrl) {
try { try {
contentAnchorPane.getChildren().removeAll(); contentAnchorPane.getChildren().removeAll();
contentAnchorPane.getChildren().clear(); contentAnchorPane.getChildren().clear();
contentAnchorPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentAnchorPane.getChildren().addAll((Pane) loader.load());
} catch (javafx.fxml.LoadException e) { } catch (javafx.fxml.LoadException e) {
System.err.println(e.getCause()); System.err.println(e.getCause());
} catch (IOException e) { } catch (IOException e) {
@@ -87,37 +87,23 @@ public class CanvasController {
// starts the timer and reads events from each boat's time line // starts the timer and reads events from each boat's time line
timer.start(); timer.start();
int i = 0;
Double maxDuration = 0.0; Double maxDuration = 0.0;
Timeline maxTimeline = null;
for (TimelineInfo timelineInfo : timelineInfos.values()) { for (TimelineInfo timelineInfo : timelineInfos.values()) {
Timeline timeline = timelineInfo.getTimeline(); Timeline timeline = timelineInfo.getTimeline();
System.out.println(); System.out.println();
if (/*timeline.getTotalDuration().greaterThanOrEqualTo(maxDuration)*/ true){ if (timeline.getTotalDuration().toMillis() >= maxDuration) {
maxDuration = timeline.getTotalDuration().toMillis();
} maxTimeline = timeline;
if (i == timelineInfos.values().size() - 1) {
timeline.setOnFinished(event -> {
setContentPane("/FinishView.fxml");
for (Boat boat : race.getFinishedBoats()) {
System.out.println(boat.getTeamName());
}
});
System.out.println("B");
}
else{
System.out.println("A");
} }
timeline.play(); timeline.play();
i++;
} }
maxTimeline.setOnFinished(event -> loadRaceResultView());
} }
/** /**
@@ -210,7 +196,6 @@ public class CanvasController {
gc.setFill(color); gc.setFill(color);
gc.fillRect(x,y,0.5,0.5); gc.fillRect(x,y,0.5,0.5);
//gc.fillOval(x, y, 0.5, 0.5);
} }
/** /**
@@ -221,10 +206,14 @@ public class CanvasController {
private void drawGateMark(GateMark gateMark) { private void drawGateMark(GateMark gateMark) {
Color color = Color.BLUE; Color color = Color.BLUE;
if (gateMark.getName().equals("Start") || gateMark.getName().equals("Finish")){ if (gateMark.getName().equals("Start")){
color = Color.RED; color = Color.RED;
} }
if (gateMark.getName().equals("Finish")){
color = Color.GREEN;
}
drawSingleMark(gateMark.getSingleMark1(), color); drawSingleMark(gateMark.getSingleMark1(), color);
drawSingleMark(gateMark.getSingleMark2(), color); drawSingleMark(gateMark.getSingleMark2(), color);
@@ -232,15 +221,18 @@ public class CanvasController {
gc.setStroke(color); gc.setStroke(color);
//@todo Put this in Mark class // Convert lat/lon to x,y
double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000; double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000;
double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000; double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000;
double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000; double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000;
double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000; double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000;
gc.setLineWidth(0.1); gc.setLineWidth(0.07);
gc.strokeLine(x1, y1, x2, y2); gc.strokeLine(x1, y1, x2, y2);
} }
public Race getRace(){
return this.race;
}
} }
@@ -55,13 +55,18 @@ public class RaceController {
//get race size //get race size
int numberOfBoats = (int) fp.getRaceSize(); int numberOfBoats = (int) fp.getRaceSize();
int boatsAdded = 0;
//get time scale //get time scale
double timeScale = fp.getTimeScale(); double timeScale = fp.getTimeScale();
race.setTimeScale(timeScale); race.setTimeScale(timeScale);
for (Map<String, Object> team : teams) { for (Map<String, Object> team : teams) {
boatNames.add((String) team.get("team-name")); if (boatsAdded < numberOfBoats){
boatNames.add((String) team.get("team-name"));
race.addBoat(new Boat(team.get("team-name").toString(), (Double) (team.get("velocity"))));
}
boatsAdded++;
} }
// Shuffle team names // Shuffle team names
@@ -72,11 +77,6 @@ public class RaceController {
return null; return null;
} }
// Add boats to the race
for (int i = 0; i < numberOfBoats; i++) {
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
}
CourseParser cp = new CourseParser("doc/examples/course.xml"); CourseParser cp = new CourseParser("doc/examples/course.xml");
race.addCourse(cp.getCourse()); race.addCourse(cp.getCourse());
@@ -2,8 +2,10 @@ package seng302.controllers;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import seng302.models.Race;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@@ -13,15 +15,23 @@ import java.util.ResourceBundle;
*/ */
public class RaceResultController implements Initializable{ public class RaceResultController implements Initializable{
@FXML private AnchorPane window; @FXML private AnchorPane window;
@FXML private Parent raceView; @FXML private VBox resultsVBox;
@FXML private RaceController raceViewController; private Race race;
public void setResults(){ RaceResultController(Race race){
System.out.println("HI MOM"); this.race = race;
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
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()));
boatPosition--;
}
} }
} }
+1
View File
@@ -135,6 +135,7 @@ public class Race {
} }
public void setBoatFinished(Boat boat){ public void setBoatFinished(Boat boat){
System.out.println(boat.getTeamName() + " finished");
this.finishingOrder.add(boat); this.finishingOrder.add(boat);
} }
} }
+26 -9
View File
@@ -1,36 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import java.lang.*?> <?import java.lang.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane maxHeight="1080.0" maxWidth="1920.0" minHeight="1080.0" minWidth="1920.0" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.RaceResultController"> <AnchorPane fx:id="raceResults" maxHeight="1080.0" maxWidth="1920.0" minHeight="1080.0" minWidth="1920.0" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<GridPane layoutX="444.0" layoutY="256.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane layoutX="444.0" layoutY="256.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="620.1734008789062" minWidth="10.0" prefWidth="493.2829895019531" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="862.0581665039062" minWidth="10.0" prefWidth="786.7170104980469" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="112.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="112.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="99.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="348.0" minHeight="10.0" prefHeight="99.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="348.0" minHeight="7.0" prefHeight="53.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="348.0" minHeight="7.0" prefHeight="88.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="653.0" minHeight="10.0" prefHeight="62.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="348.0" minHeight="0.0" prefHeight="278.3376770019531" vgrow="SOMETIMES" />
<RowConstraints maxHeight="812.0" minHeight="10.0" prefHeight="753.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="653.0" minHeight="0.0" prefHeight="98.66232299804688" vgrow="SOMETIMES" />
<RowConstraints maxHeight="812.0" minHeight="10.0" prefHeight="418.4577941894531" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Race Results:" textAlignment="CENTER" wrappingWidth="640.244140625" GridPane.rowIndex="3"> <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Race Results:" wrappingWidth="616.5260620117188" GridPane.rowIndex="2">
<font> <font>
<Font size="45.0" /> <Font size="45.0" />
</font> </font>
<GridPane.margin>
<Insets left="50.0" />
</GridPane.margin>
</Text> </Text>
<VBox fx:id="resultsVBox" prefHeight="200.0" prefWidth="100.0" GridPane.rowIndex="4" /> <VBox fx:id="resultsVBox" prefHeight="44.0" prefWidth="571.0" GridPane.rowIndex="3">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Finish!" textAlignment="CENTER" wrappingWidth="640.0234375" GridPane.rowIndex="1"> <opaqueInsets>
<Insets />
</opaqueInsets>
<GridPane.margin>
<Insets left="50.0" />
</GridPane.margin>
<padding>
<Insets top="60.0" />
</padding></VBox>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Finish!" wrappingWidth="623.9530334472656" GridPane.rowIndex="1">
<font> <font>
<Font size="75.0" /> <Font size="75.0" />
</font> </font>
<GridPane.margin>
<Insets left="50.0" />
</GridPane.margin>
</Text> </Text>
</children> </children>
</GridPane> </GridPane>
+1 -1
View File
@@ -18,7 +18,7 @@
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: lightblue;" GridPane.columnIndex="1" GridPane.rowSpan="3"> <AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: lightblue;" GridPane.columnIndex="1" GridPane.rowSpan="3" fx:id="contentAnchorPane">
<children> <children>
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" /> <Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
</children> </children>