aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/server/Main.java2
-rw-r--r--src/ch/epfl/xblast/server/Server.java17
2 files changed, 16 insertions, 3 deletions
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 {
16 /** 16 /**
17 * Starts a new server. 17 * Starts a new server.
18 * 18 *
19 * @param args arguments given to the server (i.e. number of players required for the game to start) 19 * @param args arguments given to the server
20 */ 20 */
21 public static void main(String[] args) { 21 public static void main(String[] args) {
22 Integer expectedClients = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 0)); 22 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
@@ -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 /**