From 355f0c157e537aff4b256c7363647ae596c8610d Mon Sep 17 00:00:00 2001 From: Stef Date: Thu, 18 Sep 2025 15:50:37 +0200 Subject: [PATCH] Update TicTacToe.java --- .../org/toop/game/tictactoe/TicTacToe.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/org/toop/game/tictactoe/TicTacToe.java b/src/main/java/org/toop/game/tictactoe/TicTacToe.java index ca405ce..86edebc 100644 --- a/src/main/java/org/toop/game/tictactoe/TicTacToe.java +++ b/src/main/java/org/toop/game/tictactoe/TicTacToe.java @@ -68,6 +68,49 @@ public class TicTacToe extends GameBase implements Runnable { private void gameThread() { while (true) { + ParsedCommand cmd = takeFromCommandQueue(); + + // Make sure command was received + if (cmd == null){ + continue; + } + + switch (cmd.command) { + case TicTacToeServerCommand.MOVE:{ + // TODO: Check if it is this player's turn, not required for local or AI play. + + // Convert given argument to integer + Object arg = cmd.arguments.getFirst(); + int index; + try{ + index = Integer.parseInt((String)arg); + } + catch (Exception e){ + logger.error("Error parsing argument to String or Integer"); + continue; + } + + // Attempt to play the move + State state = play(index); + + // Check move result + switch (state){ + case State.WIN:{ + // Win + } + case State.DRAW:{ + // Draw + } + case State.NORMAL:{ + // Nothing wrong? + } + case State.INVALID:{ + // Invalid move + } + } + + } + } // TODO: Game use the commandQueue to get the commands. }