aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/server/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/xblast/server/Server.java')
-rw-r--r--src/ch/epfl/xblast/server/Server.java17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/ch/epfl/xblast/server/Server.java b/src/ch/epfl/xblast/server/Server.java
index 4674cbb..3f486c6 100644
--- a/src/ch/epfl/xblast/server/Server.java
+++ b/src/ch/epfl/xblast/server/Server.java
@@ -34,6 +34,15 @@ public class Server {
34 public static final byte OBSERVER = -1; 34 public static final byte OBSERVER = -1;
35 35
36 /** 36 /**
37 * Print a log message on the console.
38 *
39 * @param message message to be printed
40 */
41 private static void log(String message) {
42 System.out.println("[LOG] " + message);
43 }
44
45 /**
37 * A Channel. 46 * A Channel.
38 */ 47 */
39 private static class Channel { 48 private static class Channel {
@@ -234,7 +243,6 @@ public class Server {
234 do { 243 do {
235 clientAction = this.acceptAction(); 244 clientAction = this.acceptAction();
236 } while (clientAction.getValue() != PlayerAction.JOIN_GAME); 245 } while (clientAction.getValue() != PlayerAction.JOIN_GAME);
237
238 return clientAction.getKey(); 246 return clientAction.getKey();
239 } 247 }
240 248
@@ -272,6 +280,7 @@ public class Server {
272 * Run the whole server. 280 * Run the whole server.
273 */ 281 */
274 public void run() { 282 public void run() {
283 log("Starting the server...");
275 this.acceptClientRegistrations(); 284 this.acceptClientRegistrations();
276 this.runGame(); 285 this.runGame();
277 this.channel.closeChannel(); 286 this.channel.closeChannel();
@@ -291,13 +300,17 @@ public class Server {
291 */ 300 */
292 private void runGame() { 301 private void runGame() {
293 GameState gameState = GameState.DEFAULT_GAME_STATE; 302 GameState gameState = GameState.DEFAULT_GAME_STATE;
294
295 while (!gameState.isGameOver()) { 303 while (!gameState.isGameOver()) {
296 long computationStartTime = System.nanoTime(); 304 long computationStartTime = System.nanoTime();
297 gameState = updateGameState(gameState); 305 gameState = updateGameState(gameState);
298 broadcastGameState(gameState); 306 broadcastGameState(gameState);
299 Time.sleep(REFRESH_RATE - (computationStartTime - System.nanoTime())); 307 Time.sleep(REFRESH_RATE - (computationStartTime - System.nanoTime()));
300 } 308 }
309
310 if (gameState.winner().isPresent())
311 log("Winner : PLAYER_" + gameState.winner());
312 else
313 log("There is no winner.");
301 } 314 }
302 315
303 /** 316 /**