mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
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:
@@ -9,7 +9,7 @@
|
||||
},
|
||||
{
|
||||
"team-name": "Artemis Racing",
|
||||
"velocity": 10.3
|
||||
"velocity": 59.3
|
||||
},
|
||||
{
|
||||
"team-name": "Emirates Team New Zealand",
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
{
|
||||
"team-name": "Groupama Team France",
|
||||
"velocity": 9.9
|
||||
"velocity": 29.9
|
||||
},
|
||||
{
|
||||
"team-name": "Land Rover BAR",
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<configurations>
|
||||
<race-name>AC35</race-name>
|
||||
<race-size>6</race-size>
|
||||
<time-scale>2.0</time-scale>
|
||||
<time-scale>1.0</time-scale>
|
||||
</configurations>
|
||||
|
||||
|
||||
@@ -40,23 +40,23 @@ public class CanvasController {
|
||||
private GraphicsContext gc;
|
||||
private HashMap<Boat, TimelineInfo> timelineInfos;
|
||||
|
||||
private AnchorPane raceResults;
|
||||
|
||||
private final double ORIGIN_LAT = 32.320504;
|
||||
private final double ORIGIN_LON = -64.857063;
|
||||
private final double VIEW_CORNER_LAT = 32.280808;
|
||||
private final double VIEW_CORNER_LON = -64.858401;
|
||||
|
||||
|
||||
@FXML
|
||||
private AnchorPane contentAnchorPane;
|
||||
|
||||
@FXML
|
||||
private RaceResultController raceResultController;
|
||||
private void loadRaceResultView() {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml"));
|
||||
loader.setController(new RaceResultController(race));
|
||||
|
||||
private void setContentPane(String jfxUrl) {
|
||||
try {
|
||||
contentAnchorPane.getChildren().removeAll();
|
||||
contentAnchorPane.getChildren().clear();
|
||||
contentAnchorPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
|
||||
contentAnchorPane.getChildren().addAll((Pane) loader.load());
|
||||
|
||||
} catch (javafx.fxml.LoadException e) {
|
||||
System.err.println(e.getCause());
|
||||
} catch (IOException e) {
|
||||
@@ -87,37 +87,23 @@ public class CanvasController {
|
||||
// starts the timer and reads events from each boat's time line
|
||||
timer.start();
|
||||
|
||||
int i = 0;
|
||||
Double maxDuration = 0.0;
|
||||
Timeline maxTimeline = null;
|
||||
|
||||
for (TimelineInfo timelineInfo : timelineInfos.values()) {
|
||||
|
||||
Timeline timeline = timelineInfo.getTimeline();
|
||||
System.out.println();
|
||||
|
||||
if (/*timeline.getTotalDuration().greaterThanOrEqualTo(maxDuration)*/ true){
|
||||
|
||||
}
|
||||
|
||||
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");
|
||||
if (timeline.getTotalDuration().toMillis() >= maxDuration) {
|
||||
maxDuration = timeline.getTotalDuration().toMillis();
|
||||
maxTimeline = timeline;
|
||||
}
|
||||
|
||||
timeline.play();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
maxTimeline.setOnFinished(event -> loadRaceResultView());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +196,6 @@ public class CanvasController {
|
||||
|
||||
gc.setFill(color);
|
||||
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) {
|
||||
Color color = Color.BLUE;
|
||||
|
||||
if (gateMark.getName().equals("Start") || gateMark.getName().equals("Finish")){
|
||||
if (gateMark.getName().equals("Start")){
|
||||
color = Color.RED;
|
||||
}
|
||||
|
||||
if (gateMark.getName().equals("Finish")){
|
||||
color = Color.GREEN;
|
||||
}
|
||||
|
||||
drawSingleMark(gateMark.getSingleMark1(), color);
|
||||
drawSingleMark(gateMark.getSingleMark2(), color);
|
||||
|
||||
@@ -232,15 +221,18 @@ public class CanvasController {
|
||||
|
||||
gc.setStroke(color);
|
||||
|
||||
//@todo Put this in Mark class
|
||||
// Convert lat/lon to x,y
|
||||
double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000;
|
||||
double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000;
|
||||
|
||||
double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000;
|
||||
double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000;
|
||||
|
||||
gc.setLineWidth(0.1);
|
||||
|
||||
gc.setLineWidth(0.07);
|
||||
gc.strokeLine(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public Race getRace(){
|
||||
return this.race;
|
||||
}
|
||||
}
|
||||
@@ -55,13 +55,18 @@ public class RaceController {
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = (int) fp.getRaceSize();
|
||||
int boatsAdded = 0;
|
||||
|
||||
//get time scale
|
||||
double timeScale = fp.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
|
||||
for (Map<String, Object> team : teams) {
|
||||
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
|
||||
@@ -72,11 +77,6 @@ public class RaceController {
|
||||
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");
|
||||
race.addCourse(cp.getCourse());
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ package seng302.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
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.util.ResourceBundle;
|
||||
@@ -13,15 +15,23 @@ import java.util.ResourceBundle;
|
||||
*/
|
||||
public class RaceResultController implements Initializable{
|
||||
@FXML private AnchorPane window;
|
||||
@FXML private Parent raceView;
|
||||
@FXML private RaceController raceViewController;
|
||||
@FXML private VBox resultsVBox;
|
||||
private Race race;
|
||||
|
||||
public void setResults(){
|
||||
System.out.println("HI MOM");
|
||||
RaceResultController(Race race){
|
||||
this.race = race;
|
||||
}
|
||||
|
||||
@Override
|
||||
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--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ public class Race {
|
||||
}
|
||||
|
||||
public void setBoatFinished(Boat boat){
|
||||
System.out.println(boat.getTeamName() + " finished");
|
||||
this.finishingOrder.add(boat);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?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>
|
||||
<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 hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="620.1734008789062" minWidth="10.0" prefWidth="493.2829895019531" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="862.0581665039062" minWidth="10.0" prefWidth="786.7170104980469" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<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="7.0" prefHeight="53.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="653.0" minHeight="10.0" prefHeight="62.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="812.0" minHeight="10.0" prefHeight="753.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="348.0" minHeight="7.0" prefHeight="88.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="348.0" minHeight="0.0" prefHeight="278.3376770019531" 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>
|
||||
<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 size="45.0" />
|
||||
</font>
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</Text>
|
||||
<VBox fx:id="resultsVBox" prefHeight="200.0" prefWidth="100.0" GridPane.rowIndex="4" />
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Finish!" textAlignment="CENTER" wrappingWidth="640.0234375" GridPane.rowIndex="1">
|
||||
<VBox fx:id="resultsVBox" prefHeight="44.0" prefWidth="571.0" GridPane.rowIndex="3">
|
||||
<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 size="75.0" />
|
||||
</font>
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</GridPane>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<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>
|
||||
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user