From e37aeb0eb425d6227e8c832b0bb5f5c9f79b0e64 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 23 May 2016 13:18:53 +0200 Subject: Print some logs in the server console (winner) --- src/ch/epfl/xblast/server/Main.java | 2 +- src/ch/epfl/xblast/server/Server.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/ch/epfl') diff --git a/src/ch/epfl/xblast/server/Main.java b/src/ch/epfl/xblast/server/Main.java index aff499b..eb29aec 100644 --- a/src/ch/epfl/xblast/server/Main.java +++ b/src/ch/epfl/xblast/server/Main.java @@ -16,7 +16,7 @@ public final class Main { /** * Starts a new server. * - * @param args arguments given to the server (i.e. number of players required for the game to start) + * @param args arguments given to the server */ public static void main(String[] args) { Integer expectedClients = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 0)); 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 @@ -33,6 +33,15 @@ public class Server { */ public static final byte OBSERVER = -1; + /** + * Print a log message on the console. + * + * @param message message to be printed + */ + private static void log(String message) { + System.out.println("[LOG] " + message); + } + /** * A Channel. */ @@ -234,7 +243,6 @@ public class Server { do { clientAction = this.acceptAction(); } while (clientAction.getValue() != PlayerAction.JOIN_GAME); - return clientAction.getKey(); } @@ -272,6 +280,7 @@ public class Server { * Run the whole server. */ public void run() { + log("Starting the server..."); this.acceptClientRegistrations(); this.runGame(); this.channel.closeChannel(); @@ -291,13 +300,17 @@ public class Server { */ private void runGame() { GameState gameState = GameState.DEFAULT_GAME_STATE; - while (!gameState.isGameOver()) { long computationStartTime = System.nanoTime(); gameState = updateGameState(gameState); broadcastGameState(gameState); Time.sleep(REFRESH_RATE - (computationStartTime - System.nanoTime())); } + + if (gameState.winner().isPresent()) + log("Winner : PLAYER_" + gameState.winner()); + else + log("There is no winner."); } /** -- cgit v1.2.3