made server send appropriate racestatus flags in the race status packet #pair[mra106, ptg19] #story[1109]

This commit is contained in:
Peter Galloway
2017-08-14 17:55:53 +12:00
parent ff92262a78
commit b9ae9c4730
3 changed files with 27 additions and 6 deletions
@@ -62,7 +62,7 @@ public class GameState implements Runnable {
yachts = new HashMap<>();
markOrder = new MarkOrder(); //This could be instantiated at some point with a select map?
startTime = System.currentTimeMillis() + 20000;
startTime = System.currentTimeMillis() + 60000;
new Thread(this).start(); //Run the auto updates on the game state
}
@@ -166,6 +166,9 @@ public class GameState implements Runnable {
public void update() {
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
previousUpdateTime = System.currentTimeMillis();
if (System.currentTimeMillis() > startTime) {
GameState.setCurrentStage(GameStages.RACING);
}
for (Yacht yacht : yachts.values()) {
yacht.update(timeInterval);
}
@@ -59,6 +59,11 @@ public class ServerToClientThread implements Runnable, Observer {
private XMLGenerator xml;
private static final int PRESTART_TIME = 60 * -1000;
private static final int WARNING_TIME = 30 * -1000;
private static final int PREPATORY_TIME = 10 * -1000;
public ServerToClientThread(Socket socket) {
this.socket = socket;
seqNo = 0;
@@ -211,8 +216,6 @@ public class ServerToClientThread implements Runnable, Observer {
}
}
} catch (Exception e) {
// TODO: 24/07/17 zyt10 - fix a logic here when a client disconnected
// serverLog("ERROR OCCURRED, CLOSING SERVER CONNECTION: " + socket.getRemoteSocketAddress().toString(), 1);
closeSocket();
return;
}
@@ -368,12 +371,26 @@ public class ServerToClientThread implements Runnable, Observer {
boatSubMessages.add(m);
}
if (GameState.getCurrentStage() == GameStages.RACING) {
raceStatus = RaceStatus.STARTED;
long timeTillStart = System.currentTimeMillis() - GameState.getStartTime();
if (GameState.getCurrentStage() == GameStages.LOBBYING) {
raceStatus = RaceStatus.PRESTART;
} else if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
raceStatus = RaceStatus.PRESTART;
if (timeTillStart > WARNING_TIME) {
raceStatus = RaceStatus.WARNING;
}
if (timeTillStart > PREPATORY_TIME) {
raceStatus = RaceStatus.PREPARATORY;
}
} else {
raceStatus = RaceStatus.WARNING;
raceStatus = RaceStatus.STARTED;
}
System.out.println("raceStatus.ger = " + raceStatus.getCode());
sendMessage(new RaceStatusMessage(1, raceStatus, GameState.getStartTime(), GameState.getWindDirection(),
GameState.getWindSpeedMMS().longValue(), GameState.getPlayers().size(),
RaceType.MATCH_RACE, 1, boatSubMessages));