From 5af3053537662af87e9201d2670129f5560fc646 Mon Sep 17 00:00:00 2001 From: fjc40 Date: Tue, 1 Aug 2017 18:15:35 +1200 Subject: [PATCH] Added shared.model.Wind class. shared.model.Race now uses Wind. It is wrapped in Property<>. #story[1093] --- .../src/main/java/shared/model/Race.java | 32 ++++++------ .../src/main/java/shared/model/Wind.java | 51 +++++++++++++++++++ 2 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 racevisionGame/src/main/java/shared/model/Wind.java diff --git a/racevisionGame/src/main/java/shared/model/Race.java b/racevisionGame/src/main/java/shared/model/Race.java index 415e9f77..2af7f464 100644 --- a/racevisionGame/src/main/java/shared/model/Race.java +++ b/racevisionGame/src/main/java/shared/model/Race.java @@ -1,7 +1,9 @@ package shared.model; import javafx.beans.property.IntegerProperty; +import javafx.beans.property.Property; import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; import network.Messages.Enums.RaceStatusEnum; import network.Messages.Enums.RaceTypeEnum; import network.Messages.LatestMessages; @@ -98,15 +100,9 @@ public abstract class Race implements Runnable { /** - * The current wind direction bearing. + * The race's wind. */ - protected Bearing windDirection; - - /** - * Wind speed (knots). - * Convert this to millimeters per second before passing to RaceStatus. - */ - protected double windSpeed; + protected Property raceWind = new SimpleObjectProperty<>(); /** @@ -169,11 +165,9 @@ public abstract class Race implements Runnable { //Race type. this.raceType = raceDataSource.getRaceType(); - //Wind speed. - this.windSpeed = 0; - //Wind direction. - this.windDirection = Bearing.fromDegrees(0); - + //Wind. + Wind wind = new Wind(Bearing.fromDegrees(0), 0); + this.raceWind.setValue(wind); } @@ -259,7 +253,7 @@ public abstract class Race implements Runnable { * @return The wind bearing. */ public Bearing getWindDirection() { - return windDirection; + return raceWind.getValue().getWindDirection(); } /** @@ -268,7 +262,15 @@ public abstract class Race implements Runnable { * @return The wind speed. */ public double getWindSpeed() { - return windSpeed; + return raceWind.getValue().getWindSpeed(); + } + + /** + * Returns the race's wind. + * @return The race's wind. + */ + public Property windProperty() { + return raceWind; } /** diff --git a/racevisionGame/src/main/java/shared/model/Wind.java b/racevisionGame/src/main/java/shared/model/Wind.java new file mode 100644 index 00000000..08d391c2 --- /dev/null +++ b/racevisionGame/src/main/java/shared/model/Wind.java @@ -0,0 +1,51 @@ +package shared.model; + + + +/** + * This class encapsulates the wind during a race. + * It has speed and a bearing. + * This is intended to be immutable. + */ +public class Wind { + + /** + * The current wind direction bearing. + */ + private Bearing windDirection; + + /** + * Wind speed (knots). + * Convert this to millimeters per second before passing to RaceStatus. + */ + private double windSpeed; + + + /** + * Constructs a new wind object, with a given direction and speed, in knots. + * @param windDirection The direction of the wind. + * @param windSpeed The speed of the wind, in knots. + */ + public Wind(Bearing windDirection, double windSpeed) { + this.windDirection = windDirection; + this.windSpeed = windSpeed; + } + + /** + * Returns the race wind's bearing. + * @return The race wind's bearing. + */ + public Bearing getWindDirection() { + return windDirection; + } + + + /** + * Returns the race wind's speed, in knots. + * @return The race wind's speed, in knots. + */ + public double getWindSpeed() { + return windSpeed; + } + +}