Implement race clock
-Added label to fxml racepane.fxml -Added calcTime method to calculate time elapsed -Added updateTime method in Race to update label text -Added setTimer in RaceController to update label text #story [16] #pair [fwy13, zwu18]
This commit is contained in:
Generated
-1
@@ -1 +0,0 @@
|
|||||||
app
|
|
||||||
Generated
+2
-17
@@ -1,27 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<resourceExtensions />
|
|
||||||
<wildcardResourcePatterns>
|
|
||||||
<entry name="!?*.java" />
|
|
||||||
<entry name="!?*.form" />
|
|
||||||
<entry name="!?*.class" />
|
|
||||||
<entry name="!?*.groovy" />
|
|
||||||
<entry name="!?*.scala" />
|
|
||||||
<entry name="!?*.flex" />
|
|
||||||
<entry name="!?*.kt" />
|
|
||||||
<entry name="!?*.clj" />
|
|
||||||
<entry name="!?*.aj" />
|
|
||||||
</wildcardResourcePatterns>
|
|
||||||
<annotationProcessing>
|
<annotationProcessing>
|
||||||
<profile default="true" name="Default" enabled="false">
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
<processorPath useClasspath="true" />
|
|
||||||
</profile>
|
|
||||||
<profile default="false" name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="true" />
|
<module name="team-7" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
<bytecodeTargetLevel>
|
<bytecodeTargetLevel>
|
||||||
|
|||||||
Generated
+8
-4
@@ -1,8 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<entry_points version="2.0" />
|
|
||||||
</component>
|
|
||||||
<component name="JavadocGenerationManager">
|
<component name="JavadocGenerationManager">
|
||||||
<option name="OUTPUT_DIRECTORY" />
|
<option name="OUTPUT_DIRECTORY" />
|
||||||
<option name="OPTION_SCOPE" value="protected" />
|
<option name="OPTION_SCOPE" value="protected" />
|
||||||
@@ -21,7 +18,14 @@
|
|||||||
<option name="OPEN_IN_BROWSER" value="true" />
|
<option name="OPEN_IN_BROWSER" value="true" />
|
||||||
<option name="OPTION_INCLUDE_LIBS" value="false" />
|
<option name="OPTION_INCLUDE_LIBS" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (5)" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="SvnConfiguration">
|
<component name="SvnConfiguration">
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package seng302.Controllers;
|
|||||||
|
|
||||||
|
|
||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
@@ -34,6 +36,9 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
ResizableRaceCanvas raceMap;
|
ResizableRaceCanvas raceMap;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
Label timer;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
TableView boatInfoTable;
|
TableView boatInfoTable;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -125,5 +130,12 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTimer(String time){
|
||||||
|
timer.setText(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableArray;
|
import javafx.collections.ObservableArray;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@@ -19,6 +21,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected ArrayList<Leg> legs;
|
protected ArrayList<Leg> legs;
|
||||||
protected RaceController controller;
|
protected RaceController controller;
|
||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
|
protected long totalTimeElapsed;
|
||||||
|
|
||||||
|
|
||||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
||||||
@@ -69,6 +72,26 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String calcTimer() {
|
||||||
|
long minutes;
|
||||||
|
long currentTimeInSeconds;
|
||||||
|
long remainingSeconds;
|
||||||
|
long hours;
|
||||||
|
|
||||||
|
currentTimeInSeconds = totalTimeElapsed / 1000;
|
||||||
|
minutes = currentTimeInSeconds / 60;
|
||||||
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
|
hours = minutes/60;
|
||||||
|
return String.format("%02d:%02d:%02d", hours, minutes, remainingSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTime(String time){
|
||||||
|
|
||||||
|
Platform.runLater(() -> {controller.setTimer(time);});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Race Simulation, playing the race start to finish with the timescale.
|
* Starts the Race Simulation, playing the race start to finish with the timescale.
|
||||||
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
|
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
|
||||||
@@ -76,23 +99,15 @@ public abstract class Race implements Runnable {
|
|||||||
private void simulateRace() {
|
private void simulateRace() {
|
||||||
|
|
||||||
long timeRaceStarted = System.currentTimeMillis();
|
long timeRaceStarted = System.currentTimeMillis();
|
||||||
long totalTimeElapsed;
|
|
||||||
|
|
||||||
long timeLoopStarted;
|
long timeLoopStarted;
|
||||||
long timeLoopEnded;
|
long timeLoopEnded;
|
||||||
long minutes;
|
|
||||||
long currentTimeInSeconds;
|
|
||||||
long remainingSeconds;
|
|
||||||
|
|
||||||
|
|
||||||
while (boatsFinished < startingBoats.size()) {
|
while (boatsFinished < startingBoats.size()) {
|
||||||
timeLoopStarted = System.currentTimeMillis();
|
timeLoopStarted = System.currentTimeMillis();
|
||||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||||
long currentTime = System.currentTimeMillis() - timeRaceStarted;
|
|
||||||
currentTimeInSeconds = currentTime / 1000;
|
|
||||||
minutes = currentTimeInSeconds / 60;
|
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
|
||||||
System.out.println(minutes + ":" + remainingSeconds);
|
|
||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
@@ -102,6 +117,7 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
controller.updateMap(startingBoats);
|
controller.updateMap(startingBoats);
|
||||||
|
updateTime(calcTimer());
|
||||||
try {
|
try {
|
||||||
timeLoopEnded = System.currentTimeMillis();
|
timeLoopEnded = System.currentTimeMillis();
|
||||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
||||||
|
|||||||
@@ -7,13 +7,15 @@
|
|||||||
|
|
||||||
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
|
||||||
<children>
|
<children>
|
||||||
<SplitPane dividerPositions="0.75" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<SplitPane dividerPositions="0.75" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
<AnchorPane fx:id="canvasBase">
|
<AnchorPane fx:id="canvasBase">
|
||||||
</AnchorPane>
|
<children>
|
||||||
|
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" />
|
||||||
|
</children></AnchorPane>
|
||||||
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" GridPane.columnIndex="1">
|
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" GridPane.columnIndex="1">
|
||||||
<children>
|
<children>
|
||||||
<TableView fx:id="boatInfoTable" prefHeight="400.0" prefWidth="146.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.bottomAnchor="0.0">
|
<TableView fx:id="boatInfoTable" prefHeight="400.0" prefWidth="146.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
||||||
<TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" />
|
<TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" />
|
||||||
|
|||||||
Reference in New Issue
Block a user