mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added mock yachts to the game state for each client #story[1047]
This commit is contained in:
@@ -15,6 +15,9 @@ import seng302.models.Yacht;
|
|||||||
public class GameState {
|
public class GameState {
|
||||||
|
|
||||||
private static Long previousUpdateTime;
|
private static Long previousUpdateTime;
|
||||||
|
private static Double windDirection = 0d;
|
||||||
|
private static Double windSpeed = 0d;
|
||||||
|
|
||||||
private static String hostIpAddress;
|
private static String hostIpAddress;
|
||||||
private static List<Player> players;
|
private static List<Player> players;
|
||||||
private static Map<Integer, Yacht> yachts;
|
private static Map<Integer, Yacht> yachts;
|
||||||
@@ -46,6 +49,10 @@ public class GameState {
|
|||||||
players.remove(player);
|
players.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addYacht(Integer sourceId, Yacht yatch) {
|
||||||
|
yachts.put(sourceId, yatch);
|
||||||
|
}
|
||||||
|
|
||||||
public static Boolean getIsRaceStarted() {
|
public static Boolean getIsRaceStarted() {
|
||||||
return isRaceStarted;
|
return isRaceStarted;
|
||||||
}
|
}
|
||||||
@@ -58,7 +65,8 @@ public class GameState {
|
|||||||
GameState.currentStage = currentStage;
|
GameState.currentStage = currentStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
|
public static void update() {
|
||||||
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
||||||
previousUpdateTime = System.currentTimeMillis();
|
previousUpdateTime = System.currentTimeMillis();
|
||||||
for (Yacht yacht : yachts.values()) {
|
for (Yacht yacht : yachts.values()) {
|
||||||
|
|||||||
@@ -57,10 +57,12 @@ public class MainServerThread extends Thread implements PacketBufferDelegate, Cl
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
|
||||||
|
GameState.update();
|
||||||
|
}
|
||||||
//RACING
|
//RACING
|
||||||
if (GameState.getCurrentStage() == GameStages.RACING) {
|
if (GameState.getCurrentStage() == GameStages.RACING) {
|
||||||
|
GameState.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package seng302.gameServer;
|
package seng302.gameServer;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
import seng302.models.Player;
|
import seng302.models.Player;
|
||||||
|
import seng302.models.Yacht;
|
||||||
import seng302.models.stream.PacketBufferDelegate;
|
import seng302.models.stream.PacketBufferDelegate;
|
||||||
import seng302.models.stream.StreamParser;
|
import seng302.models.stream.StreamParser;
|
||||||
import seng302.models.stream.packets.StreamPacket;
|
import seng302.models.stream.packets.StreamPacket;
|
||||||
@@ -11,6 +13,7 @@ import java.io.*;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
|
import seng302.utilities.GeoPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing a single connection to a Client for the purposes of sending and receiving on its own thread.
|
* A class describing a single connection to a Client for the purposes of sending and receiving on its own thread.
|
||||||
@@ -31,6 +34,7 @@ public class ServerToClientThread extends Thread {
|
|||||||
private Boolean connected = true;
|
private Boolean connected = true;
|
||||||
private Boolean updateClient = true;
|
private Boolean updateClient = true;
|
||||||
|
|
||||||
|
private Integer mockId = 100;
|
||||||
public ServerToClientThread(Socket socket) {
|
public ServerToClientThread(Socket socket) {
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
try {
|
try {
|
||||||
@@ -41,6 +45,8 @@ public class ServerToClientThread extends Thread {
|
|||||||
}
|
}
|
||||||
// threeWayHandshake();
|
// threeWayHandshake();
|
||||||
GameState.addPlayer(new Player(socket));
|
GameState.addPlayer(new Player(socket));
|
||||||
|
GameState.addYacht(mockId, new Yacht("Kappa", "Kap", new GeoPoint(0.0, 0.0), 0.0));
|
||||||
|
mockId += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import seng302.models.mark.Mark;
|
import seng302.models.mark.Mark;
|
||||||
import seng302.controllers.RaceViewController;
|
import seng302.controllers.RaceViewController;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import seng302.utilities.GeoPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Yacht class for the racing boat.
|
* Yacht class for the racing boat.
|
||||||
@@ -35,10 +38,9 @@ public class Yacht {
|
|||||||
private Integer penaltiesServed;
|
private Integer penaltiesServed;
|
||||||
private Long estimateTimeAtFinish;
|
private Long estimateTimeAtFinish;
|
||||||
private String position;
|
private String position;
|
||||||
private Double lat;
|
private GeoPoint location;
|
||||||
private Double lon;
|
private Double heading;
|
||||||
private Float heading;
|
private Double velocity;
|
||||||
private double velocity;
|
|
||||||
private Long timeTillNext;
|
private Long timeTillNext;
|
||||||
private Long markRoundTime;
|
private Long markRoundTime;
|
||||||
|
|
||||||
@@ -52,8 +54,12 @@ public class Yacht {
|
|||||||
*
|
*
|
||||||
* @param boatName Create a yacht object with name.
|
* @param boatName Create a yacht object with name.
|
||||||
*/
|
*/
|
||||||
public Yacht(String boatName) {
|
public Yacht(String boatName, String shortName, GeoPoint location, Double heading) {
|
||||||
this.boatName = boatName;
|
this.boatName = boatName;
|
||||||
|
this.shortName = shortName;
|
||||||
|
this.location = location;
|
||||||
|
this.heading = heading;
|
||||||
|
this.velocity = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,11 +93,7 @@ public class Yacht {
|
|||||||
public void update(Long timeInterval) {
|
public void update(Long timeInterval) {
|
||||||
Double secondsElapsed = timeInterval / 1000000.0;
|
Double secondsElapsed = timeInterval / 1000000.0;
|
||||||
Double metersCovered = velocity * secondsElapsed;
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
// 111111 meters is approximately 1 degree of lat/long at the equator
|
location = getGeoCoordinate(location, heading, metersCovered);
|
||||||
lat = lat + (metersCovered * Math.sin(heading * (2 * Math.PI / 360))) / 111111;
|
|
||||||
lon = lon + (metersCovered * Math.cos(heading * (2 * Math.PI / 360))) / (111111 * Math
|
|
||||||
.cos(lat * (2 * Math.PI / 360)));
|
|
||||||
// formula take from https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBoatType() {
|
public String getBoatType() {
|
||||||
@@ -219,30 +221,6 @@ public class Yacht {
|
|||||||
return nextMark;
|
return nextMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getLat() {
|
|
||||||
return lat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLat(Double lat) {
|
|
||||||
this.lat = lat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getLon() {
|
|
||||||
return lon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLon(Double lon) {
|
|
||||||
this.lon = lon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Float getHeading() {
|
|
||||||
return heading;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHeading(Float heading) {
|
|
||||||
this.heading = heading;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return boatName;
|
return boatName;
|
||||||
|
|||||||
Reference in New Issue
Block a user