mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +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:
@@ -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) {
|
||||
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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user