Merge remote-tracking branch 'remotes/origin/master' into story28
-anchors now fills stage -added time label # Conflicts: # pom.xml # src/main/java/seng302/Controllers/RaceController.java # src/main/resources/scenes/racepane.fxml #pair[fwy13, hba56] #story[761]
This commit is contained in:
@@ -6,10 +6,6 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.Controllers.Controller;
|
||||
import seng302.Controllers.MainController;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class App extends Application {
|
||||
Stage primaryStage;
|
||||
@@ -25,54 +21,62 @@ public class App extends Application {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and sets up the GUI elements
|
||||
*
|
||||
* @param primaryStage Base for all scenes
|
||||
* @throws Exception Error in initialising programme
|
||||
*/
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
this.primaryStage = primaryStage;
|
||||
primaryStage.minHeightProperty().setValue(600);
|
||||
primaryStage.minWidthProperty().setValue(780);
|
||||
//load the first container
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/mainpane.fxml");
|
||||
mainContainer = (BorderPane) loader.load(in);
|
||||
mainScene = new Scene(mainContainer, 1200, 800);
|
||||
primaryStage.setScene(mainScene);
|
||||
primaryStage.sizeToScene();
|
||||
MainController mainController = (MainController) loader.getController();
|
||||
mainController.setParent(this);
|
||||
in.close();
|
||||
//add the center
|
||||
loadPane("racepane.fxml");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
primaryStage.show();
|
||||
public void start(Stage stage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/main.fxml"));
|
||||
Parent root = loader.load();
|
||||
Scene scene = new Scene(root, 1200, 800);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads panes for use in the GUI
|
||||
*
|
||||
* @param fxmlName name of resource fxml file
|
||||
* @throws Exception critical error in loading file
|
||||
*/
|
||||
public void loadPane(String fxmlName) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/" + fxmlName);
|
||||
Parent page;
|
||||
try {
|
||||
page = (Parent) loader.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
mainContainer.getChildren().remove(mainContainer.getCenter());
|
||||
mainContainer.setCenter(page);
|
||||
Controller controller = (Controller) loader.getController();
|
||||
controller.setParent(this);
|
||||
}
|
||||
// /**
|
||||
// * Loads and sets up the GUI elements
|
||||
// *
|
||||
// * @param primaryStage Base for all scenes
|
||||
// * @throws Exception Error in initialising programme
|
||||
// */
|
||||
// @Override
|
||||
// public void start(Stage primaryStage) throws Exception {
|
||||
// this.primaryStage = primaryStage;
|
||||
// primaryStage.minHeightProperty().setValue(600);
|
||||
// primaryStage.minWidthProperty().setValue(780);
|
||||
// //load the first container
|
||||
// try {
|
||||
// FXMLLoader loader = new FXMLLoader();
|
||||
// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/main.fxml");
|
||||
// mainContainer = (BorderPane) loader.load(in);
|
||||
// mainScene = new Scene(mainContainer, 1200, 800);
|
||||
// primaryStage.setScene(mainScene);
|
||||
// primaryStage.sizeToScene();
|
||||
// MainController mainController = (MainController) loader.getController();
|
||||
// mainController.setParent(this);
|
||||
// in.close();
|
||||
// //add the center
|
||||
// loadPane("race.fxml");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// primaryStage.show();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Loads panes for use in the GUI
|
||||
// *
|
||||
// * @param fxmlName name of resource fxml file
|
||||
// * @throws Exception critical error in loading file
|
||||
// */
|
||||
// public void loadPane(String fxmlName) throws Exception {
|
||||
// FXMLLoader loader = new FXMLLoader();
|
||||
// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/" + fxmlName);
|
||||
// Parent page;
|
||||
// try {
|
||||
// page = (Parent) loader.load(in);
|
||||
// } finally {
|
||||
// in.close();
|
||||
// }
|
||||
// mainContainer.getChildren().remove(mainContainer.getCenter());
|
||||
// mainContainer.setCenter(page);
|
||||
// Controller controller = (Controller) loader.getController();
|
||||
// controller.setParent(this);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -11,27 +11,17 @@ import java.util.ResourceBundle;
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
*/
|
||||
public abstract class Controller implements Initializable {
|
||||
protected App parent;
|
||||
protected MainController parent;
|
||||
|
||||
/**
|
||||
* Sets the parent of the application
|
||||
*
|
||||
* @param parent controller
|
||||
*/
|
||||
public void setParent(App parent) {
|
||||
public void setParent(MainController parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loads a pane into the parent.
|
||||
*
|
||||
* @param fxmlName fxml resource file to be loaded
|
||||
* @throws Exception error in loading file
|
||||
*/
|
||||
public void loadPane(String fxmlName) throws Exception {
|
||||
this.parent.loadPane(fxmlName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisation class that is run on start up.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import seng302.RaceXMLReader;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@@ -7,6 +12,16 @@ import java.util.ResourceBundle;
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
*/
|
||||
public class MainController extends Controller {
|
||||
@FXML StartController startController;
|
||||
@FXML RaceController raceController;
|
||||
|
||||
|
||||
public void beginRace(int scaleFactor) {
|
||||
raceController.startRace(scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main Controller for the applications will house the menu and the displayed pane.
|
||||
@@ -16,6 +31,7 @@ public class MainController extends Controller {
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
startController.setParent(this);
|
||||
raceController.setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
|
||||
import com.github.bfsmith.geotimezone.TimeZoneLookup;
|
||||
import com.github.bfsmith.geotimezone.TimeZoneResult;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.Callback;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceXMLReader;
|
||||
@@ -18,14 +17,8 @@ import seng302.RaceXMLReader;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
@@ -34,12 +27,12 @@ public class RaceController extends Controller {
|
||||
@FXML
|
||||
GridPane canvasBase;
|
||||
|
||||
ResizableRaceCanvas raceMap;
|
||||
//user saved data for annotation display
|
||||
private ArrayList<Boolean> presetAnno;
|
||||
|
||||
ResizableRaceCanvas raceMap;
|
||||
@FXML
|
||||
GridPane startScreen;
|
||||
@FXML
|
||||
SplitPane ongoingRacePane;
|
||||
SplitPane race;
|
||||
@FXML
|
||||
CheckBox showFPS;
|
||||
@FXML
|
||||
@@ -51,6 +44,17 @@ public class RaceController extends Controller {
|
||||
@FXML
|
||||
Label timeZone;
|
||||
|
||||
@FXML
|
||||
CheckBox showName;
|
||||
@FXML
|
||||
CheckBox showAbbrev;
|
||||
@FXML
|
||||
CheckBox showSpeed;
|
||||
@FXML
|
||||
Button saveAnno;
|
||||
@FXML
|
||||
Button showSetAnno;
|
||||
|
||||
@FXML
|
||||
TableView<BoatInRace> boatInfoTable;
|
||||
@FXML
|
||||
@@ -89,26 +93,6 @@ public class RaceController extends Controller {
|
||||
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 15
|
||||
*/
|
||||
public void startRace1Min() {
|
||||
startRace(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 3
|
||||
*/
|
||||
public void startRace5Min() {
|
||||
startRace(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 1
|
||||
*/
|
||||
public void startRaceNoScaling() {
|
||||
startRace(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
@@ -131,7 +115,8 @@ public class RaceController extends Controller {
|
||||
*
|
||||
* @param scaleFactor scale value of race
|
||||
*/
|
||||
private void startRace(int scaleFactor) {
|
||||
public void startRace(int scaleFactor) {
|
||||
|
||||
RaceXMLReader raceXMLReader = null;
|
||||
try {
|
||||
raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
@@ -152,12 +137,12 @@ public class RaceController extends Controller {
|
||||
|
||||
|
||||
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
||||
race.initialiseBoats();
|
||||
ConstantVelocityRace newRace = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
||||
newRace.initialiseBoats();
|
||||
|
||||
BoatInRace[] startingBoats = new BoatInRace[race.getStartingBoats().size()];
|
||||
BoatInRace[] startingBoats = new BoatInRace[newRace.getStartingBoats().size()];
|
||||
int i = 0;
|
||||
for (BoatInRace boat : race.getStartingBoats()) {
|
||||
for (BoatInRace boat : newRace.getStartingBoats()) {
|
||||
startingBoats[i] = boat;
|
||||
i++;
|
||||
}
|
||||
@@ -172,9 +157,9 @@ public class RaceController extends Controller {
|
||||
raceMap.setVisible(true);
|
||||
|
||||
canvasBase.getChildren().add(raceMap);
|
||||
startScreen.setVisible(false);
|
||||
ongoingRacePane.setVisible(true);
|
||||
race.setVisible(true);
|
||||
|
||||
//Initialize save annotation array, fps listener, and annotation listeners
|
||||
//timezone
|
||||
RaceClock raceClock = new RaceClock(raceXMLReader.getMark());
|
||||
timeZone.textProperty().bind(raceClock.timeProperty());
|
||||
@@ -182,7 +167,7 @@ public class RaceController extends Controller {
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
|
||||
new Thread((race)).start();
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +210,7 @@ public class RaceController extends Controller {
|
||||
* Set up boat annotations
|
||||
*/
|
||||
private void initializeAnnotations() {
|
||||
presetAnno = new ArrayList<>();
|
||||
//listener for annotation
|
||||
showAnnotations.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
public void changed(ObservableValue<? extends Boolean> ov,
|
||||
@@ -233,6 +219,51 @@ public class RaceController extends Controller {
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
//listener for show name in annotation
|
||||
showName.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
public void changed(ObservableValue<? extends Boolean> ov,
|
||||
Boolean old_val, Boolean new_val) {
|
||||
raceMap.toggleAnnoName();
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
//listener for show abbreviation for annotation
|
||||
showAbbrev.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
public void changed(ObservableValue<? extends Boolean> ov,
|
||||
Boolean old_val, Boolean new_val) {
|
||||
raceMap.toggleAnnoAbbrev();
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
//listener to show speed for annotation
|
||||
showSpeed.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
public void changed(ObservableValue<? extends Boolean> ov,
|
||||
Boolean old_val, Boolean new_val) {
|
||||
raceMap.toggleAnnoSpeed();
|
||||
raceMap.update();
|
||||
}
|
||||
});
|
||||
//listener to save currently selected annotation
|
||||
saveAnno.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
presetAnno.clear();
|
||||
presetAnno.add(showName.isSelected());
|
||||
presetAnno.add(showAbbrev.isSelected());
|
||||
presetAnno.add(showSpeed.isSelected());
|
||||
}
|
||||
});
|
||||
//listener to show saved annotation
|
||||
showSetAnno.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
if (presetAnno.size() > 0) {
|
||||
showName.setSelected(presetAnno.get(0));
|
||||
showAbbrev.setSelected(presetAnno.get(1));
|
||||
showSpeed.setSelected(presetAnno.get(2));
|
||||
raceMap.update();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.RaceXMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 6/04/17.
|
||||
*/
|
||||
public class StartController extends Controller {
|
||||
|
||||
@FXML private GridPane start;
|
||||
|
||||
@FXML private TableView<BoatInRace> boatNameTable;
|
||||
@FXML private TableColumn<BoatInRace, String> boatNameColumn;
|
||||
@FXML private TableColumn<BoatInRace, String> boatCodeColumn;
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 15
|
||||
*/
|
||||
public void startRace1Min() {
|
||||
startRace(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 3
|
||||
*/
|
||||
public void startRace5Min() {
|
||||
startRace(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 1
|
||||
*/
|
||||
public void startRaceNoScaling() {
|
||||
startRace(1);
|
||||
}
|
||||
|
||||
private void startRace(Integer raceScale){
|
||||
start.setVisible(false);
|
||||
|
||||
parent.beginRace(raceScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
initialiseTables();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initialiseTables() {
|
||||
|
||||
RaceXMLReader raceXMLReader = null;
|
||||
try {
|
||||
raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
|
||||
boats = raceXMLReader.getBoats().toArray(boats);
|
||||
ObservableList<BoatInRace> observableBoats = FXCollections.observableArrayList(boats);
|
||||
boatNameTable.setItems(observableBoats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public class BoatInRace extends Boat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if boat has finished, fals eif not
|
||||
* @return true if boat has finished, false if not
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return this.finished;
|
||||
@@ -248,7 +248,7 @@ public class BoatInRace extends Boat {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position.set(Integer.toString(position + 1));
|
||||
public void setPosition(String position) {
|
||||
this.position.set(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public abstract class Race implements Runnable {
|
||||
protected RaceController controller;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
private int dnfChance = 1; //%percentage chance a boat fails at each checkpoint
|
||||
|
||||
private int lastFPS = 20;
|
||||
|
||||
@@ -31,7 +32,7 @@ public abstract class Race implements Runnable {
|
||||
protected int scaleFactor;
|
||||
|
||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||
protected int PRERACE_TIME = 5000; //time in milliseconds to pause during pre-race
|
||||
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
||||
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,16 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chance each boat has of failing at a gate or marker
|
||||
* @param chance percentage chance a boat has of failing per checkpoint.
|
||||
*/
|
||||
protected void setDnfChance(int chance) {
|
||||
if (chance >= 0 && chance <= 100) {
|
||||
dnfChance = chance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void initialiseBoats() {
|
||||
|
||||
@@ -85,7 +96,7 @@ public abstract class Race implements Runnable {
|
||||
setControllerListeners();
|
||||
initialiseBoats();
|
||||
if (timerEnabled) countdownTimer();
|
||||
simulateRace();
|
||||
//simulateRace();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,37 +111,35 @@ public abstract class Race implements Runnable {
|
||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||
*/
|
||||
protected void countdownTimer() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long startTime = currentTime + PRERACE_TIME;
|
||||
long minutes;
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
long timeLoopEnded;
|
||||
new AnimationTimer() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
||||
long minutes;
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
|
||||
while (currentTime <= startTime) {
|
||||
timeLeft = startTime - currentTime;
|
||||
if (timeLeft == 0 && controller != null) {
|
||||
updateTime("Race is starting...");
|
||||
} else {
|
||||
currentTimeInSeconds = timeLeft / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
if (controller != null) {
|
||||
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||
}
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
timeLeft = startTime - currentTime;
|
||||
if (timeLeft <= 0 && controller != null) {
|
||||
updateTime("Race is starting...");
|
||||
stop();
|
||||
simulateRace();
|
||||
} else {
|
||||
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
|
||||
minutes = currentTimeInSeconds / 60;
|
||||
remainingSeconds = currentTimeInSeconds % 60;
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
if (controller != null) {
|
||||
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||
}
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
try {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +185,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
private boolean doNotFinish() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(100) < 1;
|
||||
return rand.nextInt(100) < dnfChance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,8 +273,21 @@ public abstract class Race implements Runnable {
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||
}
|
||||
//Update the boat display table in the GUI to reflect the leg change
|
||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
boat.setPosition(startingBoats.indexOf(boat));
|
||||
updatePositions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update position of boats in race, no position if on starting leg or DNF.
|
||||
*/
|
||||
private void updatePositions() {
|
||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
for(BoatInRace boat: startingBoats) {
|
||||
if(boat != null) {
|
||||
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
||||
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
||||
boat.setPosition("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import seng302.GraphCoordinate;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This creates a JavaFX Canvas that is fills it's parent.
|
||||
@@ -25,6 +26,9 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
private BoatInRace[] boats;
|
||||
private RaceController controller;
|
||||
private boolean raceAnno = true;
|
||||
private boolean annoName = true;
|
||||
private boolean annoAbbrev = true;
|
||||
private boolean annoSpeed = true;
|
||||
private ArrayList<GPSCoordinate> raceBoundaries;
|
||||
double[] xpoints = {}, ypoints = {};
|
||||
|
||||
@@ -163,11 +167,25 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
* Display given name and speed of boat at a graph coordinate
|
||||
*
|
||||
* @param name name of the boat
|
||||
* @param abbrev abbreviation of the boat name
|
||||
* @param speed speed of the boat
|
||||
* @param coordinate coordinate the text appears
|
||||
*/
|
||||
private void displayText(String name, double speed, GraphCoordinate coordinate) {
|
||||
String text = String.format("%s, %2$.2fkn", name, speed);
|
||||
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) {
|
||||
String text = "";
|
||||
//Check name toggle value
|
||||
if (annoName){
|
||||
text += String.format("%s ", name);
|
||||
}
|
||||
//Check abbreviation toggle value
|
||||
if (annoAbbrev){
|
||||
text += String.format("%s ", abbrev);
|
||||
}
|
||||
//Check speed toggle value
|
||||
if (annoSpeed){
|
||||
text += String.format("%.2fkn", speed);
|
||||
}
|
||||
//String text = String.format("%s, %2$.2fkn", name, speed);
|
||||
long xCoord = coordinate.getX() + 20;
|
||||
long yCoord = coordinate.getY();
|
||||
if (xCoord + (text.length() * 7) >= getWidth()) {
|
||||
@@ -187,6 +205,9 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
this.updateBoats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw boundary of the race.
|
||||
*/
|
||||
public void drawBoundaries() {
|
||||
if (this.raceBoundaries == null) {
|
||||
return;
|
||||
@@ -263,6 +284,39 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle name display in annotation
|
||||
*/
|
||||
public void toggleAnnoName() {
|
||||
if (annoName) {
|
||||
annoName = false;
|
||||
} else {
|
||||
annoName = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle abbreviation display in annotation
|
||||
*/
|
||||
public void toggleAnnoAbbrev() {
|
||||
if (annoAbbrev) {
|
||||
annoAbbrev = false;
|
||||
} else {
|
||||
annoAbbrev = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle speed display in annotation
|
||||
*/
|
||||
public void toggleAnnoSpeed() {
|
||||
if (annoSpeed) {
|
||||
annoSpeed = false;
|
||||
} else {
|
||||
annoSpeed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws boats while race in progress, when leg heading is set.
|
||||
*/
|
||||
@@ -283,7 +337,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.MainController">
|
||||
<children>
|
||||
<fx:include source="race.fxml" fx:id="race"/>
|
||||
<fx:include source="start.fxml" fx:id="start"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<BorderPane fx:id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
|
||||
prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="seng302.Controllers.MainController"/>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
|
||||
<SplitPane fx:id="race" dividerPositions="0.7" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
||||
<items>
|
||||
<GridPane fx:id="canvasBase">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||
<children>
|
||||
<Accordion>
|
||||
<panes>
|
||||
<TitledPane animated="false" text="Annotation Control">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showAnnotations" layoutX="-2.0" layoutY="14.0" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="26.0" />
|
||||
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="52.0" />
|
||||
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="78.0" />
|
||||
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Annotation" AnchorPane.topAnchor="104.0" />
|
||||
<Button fx:id="showSetAnno" layoutX="11.0" layoutY="139.0" mnemonicParsing="false" text="Show Set Annotation" AnchorPane.topAnchor="139.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
<TitledPane animated="false" text="FPS Control">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" layoutX="-14.0" layoutY="13.0" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
</panes>
|
||||
</Accordion>
|
||||
</children>
|
||||
</Pane>
|
||||
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.halignment="RIGHT" GridPane.valignment="BOTTOM">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" GridPane.halignment="LEFT" GridPane.valignment="BOTTOM">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||
<children>
|
||||
<TableView fx:id="boatInfoTable" layoutX="-2.0" prefHeight="600.0" prefWidth="264.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="-62.0" AnchorPane.topAnchor="0.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
||||
<TableColumn fx:id="boatTeamColumn" prefWidth="100.0" text="Team" />
|
||||
<TableColumn fx:id="boatMarkColumn" prefWidth="130.0" text="Mark" />
|
||||
<TableColumn fx:id="boatSpeedColumn" prefWidth="75.0" text="Speed" />
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
@@ -1,121 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
||||
<children>
|
||||
<GridPane fx:id="startScreen" prefHeight="600.0" prefWidth="780.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="189.0" minWidth="10.0" prefWidth="93.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="372.0" minWidth="10.0" prefWidth="184.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="192.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="273.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="57.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="241.0" minHeight="10.0" prefHeight="102.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="383.0" minHeight="10.0" prefHeight="227.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="59.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="178.0" minHeight="10.0" prefHeight="178.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Select Your Race Scaling:" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="23.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button mnemonicParsing="false" onAction="#startRace1Min" text="15x faster" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<Button mnemonicParsing="false" onAction="#startRaceNoScaling" text="No scaling" GridPane.columnIndex="3" GridPane.rowIndex="2" />
|
||||
<Button mnemonicParsing="false" onAction="#startRace5Min" text="3x faster" GridPane.columnIndex="2" GridPane.rowIndex="2" />
|
||||
<Label alignment="CENTER" text="Race will take ~1 minute" GridPane.columnIndex="1" GridPane.rowIndex="3">
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
<font>
|
||||
<Font size="10.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" layoutX="99.0" layoutY="407.0" text="Race will take ~5 minutes" GridPane.columnIndex="2" GridPane.rowIndex="3">
|
||||
<font>
|
||||
<Font size="10.0" />
|
||||
</font>
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
</Label>
|
||||
<Label alignment="CENTER" layoutX="279.0" layoutY="407.0" text="Race will take ~15 minutes" GridPane.columnIndex="3" GridPane.rowIndex="3">
|
||||
<font>
|
||||
<Font size="10.0" />
|
||||
</font>
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.7" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<items>
|
||||
<GridPane fx:id="canvasBase">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||
<children>
|
||||
<TitledPane fx:id="userControl" animated="false" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
</children>
|
||||
</Pane>
|
||||
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" maxHeight="20.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.halignment="RIGHT" GridPane.valignment="BOTTOM">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" GridPane.halignment="LEFT" GridPane.valignment="BOTTOM">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="timeZone" GridPane.halignment="RIGHT" GridPane.valignment="BOTTOM">
|
||||
<font>
|
||||
<Font name="System Bold" size="15.0" />
|
||||
</font>
|
||||
<GridPane.margin>
|
||||
<Insets bottom="20.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||
<children>
|
||||
<TableView fx:id="boatInfoTable" layoutX="-2.0" prefHeight="600.0" prefWidth="264.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="-62.0" AnchorPane.topAnchor="0.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
||||
<TableColumn fx:id="boatTeamColumn" prefWidth="100.0" text="Team" />
|
||||
<TableColumn fx:id="boatMarkColumn" prefWidth="130.0" text="Mark" />
|
||||
<TableColumn fx:id="boatSpeedColumn" prefWidth="75.0" text="Speed" />
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<GridPane fx:id="start" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.StartController">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="189.0" minWidth="10.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="372.0" minWidth="10.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="250.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="200.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="200.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="241.0" minHeight="10.0" prefHeight="116.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="383.0" minHeight="10.0" prefHeight="257.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="50.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="53.5" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to RaceVision" GridPane.columnSpan="5" GridPane.halignment="CENTER">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRace1Min" prefWidth="100.0" text="1 Minute" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="4">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin></Button>
|
||||
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRaceNoScaling" prefWidth="100.0" text="15 Minutes" GridPane.columnIndex="3" GridPane.halignment="LEFT" GridPane.rowIndex="4" />
|
||||
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRace5Min" prefWidth="100.0" text="5 Minutes" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
<Label text="Select Race Duration:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||
<TableView fx:id="boatNameTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1">
|
||||
<columns>
|
||||
<TableColumn fx:id="boatNameColumn" prefWidth="360.0" style="-fx-font-size: 16;" text="Team Name" />
|
||||
<TableColumn fx:id="boatCodeColumn" prefWidth="133.0" style="-fx-font-size: 16;" text="Code" />
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
</GridPane>
|
||||
@@ -31,6 +31,7 @@ public class RaceTest {
|
||||
|
||||
Race race = new ConstantVelocityRace(boats, legs, null, 5);
|
||||
race.disableTimer();
|
||||
race.setDnfChance(0);
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.run();
|
||||
|
||||
@@ -49,8 +50,10 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
|
||||
race.checkPosition(finishedBoat, 100000);
|
||||
assertEquals(race.boatsFinished, 1);
|
||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
@@ -68,6 +71,7 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
@@ -84,6 +88,7 @@ public class RaceTest {
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
@@ -96,7 +101,10 @@ public class RaceTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
/*@Test
|
||||
|
||||
//Test temporarily removed as countdown timer now uses animation timer
|
||||
|
||||
public void timerDelaysByHalfSecond() {
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
@@ -108,9 +116,10 @@ public class RaceTest {
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.countdownTimer();
|
||||
|
||||
assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
//assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
System.out.println(System.currentTimeMillis() - timeStarted);
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void scalerScalesVelocityCorrectly() {
|
||||
@@ -130,6 +139,8 @@ public class RaceTest {
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||
race.setDnfChance(0);
|
||||
|
||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
|
||||
Reference in New Issue
Block a user