mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Game state now updates based on boat position. Arrows drawn as boat travels course. Currently do not point in correct direction, also the sparkline does not work.
#bug #refactor #implement #story[1118]
This commit is contained in:
@@ -2,7 +2,11 @@ package seng302.model;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import seng302.model.stream.parser.RaceStartData;
|
||||
import seng302.model.stream.parser.RaceStatusData;
|
||||
|
||||
@@ -12,22 +16,27 @@ import seng302.model.stream.parser.RaceStatusData;
|
||||
*/
|
||||
public class RaceState {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CollisionListener {
|
||||
void notifyCollision(GeoPoint location);
|
||||
}
|
||||
|
||||
// private final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
private final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
private double windSpeed;
|
||||
private double windDirection;
|
||||
private ReadOnlyDoubleWrapper windDirection = new ReadOnlyDoubleWrapper();
|
||||
private long raceTime;
|
||||
private long expectedStartTime;
|
||||
private boolean isRaceStarted = false;
|
||||
// long timeTillStart;
|
||||
private List<ClientYacht> collisions = new ArrayList<>();
|
||||
private List<CollisionListener> collisionListeners = new ArrayList<>();
|
||||
|
||||
public RaceState() {
|
||||
}
|
||||
|
||||
public void updateState (RaceStatusData data) {
|
||||
this.windSpeed = data.getWindSpeed();
|
||||
this.windDirection = data.getWindDirection();
|
||||
this.windDirection.set(data.getWindDirection());
|
||||
this.raceTime = data.getCurrentTime();
|
||||
this.expectedStartTime = data.getExpectedStartTime();
|
||||
this.isRaceStarted = data.isRaceStarted();
|
||||
@@ -54,8 +63,8 @@ public class RaceState {
|
||||
return windSpeed;
|
||||
}
|
||||
|
||||
public double getWindDirection() {
|
||||
return windDirection;
|
||||
public ReadOnlyDoubleProperty windDirectionProperty() {
|
||||
return windDirection.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public long getRaceTime() {
|
||||
@@ -69,4 +78,19 @@ public class RaceState {
|
||||
public boolean isRaceStarted () {
|
||||
return isRaceStarted;
|
||||
}
|
||||
|
||||
public void storeCollision(ClientYacht yacht) {
|
||||
collisions.add(yacht);
|
||||
for (CollisionListener collisionListener : collisionListeners) {
|
||||
collisionListener.notifyCollision(yacht.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public void addCollisionListener(CollisionListener collisionListener) {
|
||||
collisionListeners.add(collisionListener);
|
||||
}
|
||||
|
||||
public void removeCollisionListener(CollisionListener collisionListener) {
|
||||
collisionListeners.remove(collisionListener);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user