mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +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:
@@ -8,6 +8,8 @@ import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
||||
import javafx.beans.property.ReadOnlyIntegerWrapper;
|
||||
import javafx.beans.property.ReadOnlyLongProperty;
|
||||
import javafx.beans.property.ReadOnlyLongWrapper;
|
||||
import javafx.scene.paint.Color;
|
||||
@@ -28,6 +30,11 @@ public class ClientYacht extends Observable {
|
||||
Boolean sailsIn, double velocity);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MarkRoundingListener {
|
||||
void notifyRounding(ClientYacht yacht, CompoundMark markPassed, int legNumber);
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ClientYacht.class);
|
||||
|
||||
|
||||
@@ -52,11 +59,12 @@ public class ClientYacht extends Observable {
|
||||
|
||||
//CLIENT SIDE
|
||||
private List<YachtLocationListener> locationListeners = new ArrayList<>();
|
||||
private List<MarkRoundingListener> markRoundingListeners = new ArrayList<>();
|
||||
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
||||
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
|
||||
private ReadOnlyIntegerWrapper placingProperty = new ReadOnlyIntegerWrapper();
|
||||
private CompoundMark lastMarkRounded;
|
||||
private Integer positionInt = 0;
|
||||
private Color colour;
|
||||
|
||||
public ClientYacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
@@ -145,12 +153,16 @@ public class ClientYacht extends Observable {
|
||||
this.estimateTimeAtFinish = estimateTimeAtFinish;
|
||||
}
|
||||
|
||||
public Integer getPositionInteger() {
|
||||
return positionInt;
|
||||
public Integer getPlacing() {
|
||||
return placingProperty.get();
|
||||
}
|
||||
|
||||
public void setPositionInteger(Integer position) {
|
||||
this.positionInt = position;
|
||||
public void setPlacing(Integer position) {
|
||||
placingProperty.set(position);
|
||||
}
|
||||
|
||||
public ReadOnlyIntegerProperty placingProperty() {
|
||||
return placingProperty.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public void updateVelocityProperty(double velocity) {
|
||||
@@ -239,14 +251,6 @@ public class ClientYacht extends Observable {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
// public Double getCurrentVelocity() {
|
||||
// return currentVelocity;
|
||||
// }
|
||||
//
|
||||
// public void setCurrentVelocity(Double currentVelocity) {
|
||||
// this.currentVelocity = currentVelocity;
|
||||
// }
|
||||
|
||||
|
||||
public void updateLocation(double lat, double lng, double heading, double velocity) {
|
||||
setLocation(lat, lng);
|
||||
@@ -262,7 +266,25 @@ public class ClientYacht extends Observable {
|
||||
locationListeners.add(listener);
|
||||
}
|
||||
|
||||
public void addMarkRoundingListener(MarkRoundingListener listener) {
|
||||
markRoundingListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeMarkRoundingListener(MarkRoundingListener listener) {
|
||||
markRoundingListeners.remove(listener);
|
||||
}
|
||||
|
||||
public boolean getSailIn () {
|
||||
return sailIn;
|
||||
}
|
||||
|
||||
public void roundMark(CompoundMark mark, long markRoundTime, long timeSinceLastMark) {
|
||||
this.markRoundTime = markRoundTime;
|
||||
timeSinceLastMarkProperty.set(timeSinceLastMark);
|
||||
lastMarkRounded = mark;
|
||||
legNumber += 1;
|
||||
for (MarkRoundingListener listener : markRoundingListeners) {
|
||||
listener.notifyRounding(this, lastMarkRounded, legNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Observer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.server.messages.BoatStatus;
|
||||
import seng302.gameServer.messages.BoatStatus;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package seng302.model.mark;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import seng302.gameServer.server.messages.RoundingSide;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.utilities.GeoUtility;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package seng302.model.mark;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import seng302.gameServer.server.messages.RoundingSide;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.GeoPoint;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.gameServer.server.messages.RoundingSide;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.stream.xml.generator.Race;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.utilities.XMLGenerator;
|
||||
|
||||
Reference in New Issue
Block a user