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 {
|
||||
|
||||
private static Long previousUpdateTime;
|
||||
private static Double windDirection = 0d;
|
||||
private static Double windSpeed = 0d;
|
||||
|
||||
private static String hostIpAddress;
|
||||
private static List<Player> players;
|
||||
private static Map<Integer, Yacht> yachts;
|
||||
@@ -46,6 +49,10 @@ public class GameState {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public static void addYacht(Integer sourceId, Yacht yatch) {
|
||||
yachts.put(sourceId, yatch);
|
||||
}
|
||||
|
||||
public static Boolean getIsRaceStarted() {
|
||||
return isRaceStarted;
|
||||
}
|
||||
@@ -58,7 +65,8 @@ public class GameState {
|
||||
GameState.currentStage = currentStage;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
public static void update() {
|
||||
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
for (Yacht yacht : yachts.values()) {
|
||||
|
||||
@@ -57,10 +57,12 @@ public class MainServerThread extends Thread implements PacketBufferDelegate, Cl
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
|
||||
GameState.update();
|
||||
}
|
||||
//RACING
|
||||
if (GameState.getCurrentStage() == GameStages.RACING) {
|
||||
|
||||
GameState.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package seng302.gameServer;
|
||||
|
||||
import java.util.Random;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.models.Player;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.models.stream.PacketBufferDelegate;
|
||||
import seng302.models.stream.StreamParser;
|
||||
import seng302.models.stream.packets.StreamPacket;
|
||||
@@ -11,6 +13,7 @@ import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.zip.CRC32;
|
||||
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.
|
||||
@@ -31,6 +34,7 @@ public class ServerToClientThread extends Thread {
|
||||
private Boolean connected = true;
|
||||
private Boolean updateClient = true;
|
||||
|
||||
private Integer mockId = 100;
|
||||
public ServerToClientThread(Socket socket) {
|
||||
this.socket = socket;
|
||||
try {
|
||||
@@ -41,6 +45,8 @@ public class ServerToClientThread extends Thread {
|
||||
}
|
||||
// threeWayHandshake();
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user