From a9e68bcf4e6440d83bb3c48d535d692d5145c91f Mon Sep 17 00:00:00 2001 From: Sherif Ashraf Date: Wed, 14 Jan 2026 08:58:58 +0200 Subject: [PATCH] solve Update Turn Indicator with Offlien PvP and PvE --- .../REC_Player_vs_CPU_1768350437773.dat | Bin 0 -> 96 bytes .../network/ServerConnectionManager.java | 2 +- .../presentation/GameController.java | 29 ++++++++++-------- .../Server_connectionController.java | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 recordings/REC_Player_vs_CPU_1768350437773.dat diff --git a/recordings/REC_Player_vs_CPU_1768350437773.dat b/recordings/REC_Player_vs_CPU_1768350437773.dat new file mode 100644 index 0000000000000000000000000000000000000000..885505a710d29061ccf76ab2704398e76a01946e GIT binary patch literal 96 zcmWN?u?m176a~<$L9P8jpHRFf)&sYYh9)H}+@ztcsja`S;c(EV)u-8~u#|1_> literal 0 HcmV?d00001 diff --git a/src/main/java/com/boredxgames/tictactoeclient/domain/network/ServerConnectionManager.java b/src/main/java/com/boredxgames/tictactoeclient/domain/network/ServerConnectionManager.java index 8f06f41..734301d 100644 --- a/src/main/java/com/boredxgames/tictactoeclient/domain/network/ServerConnectionManager.java +++ b/src/main/java/com/boredxgames/tictactoeclient/domain/network/ServerConnectionManager.java @@ -52,7 +52,7 @@ public static ServerConnectionManager getInstance() { public void connect(String host, int port ) throws IOException { isIntentionalDisconnect = false; InetAddress ip = InetAddress.getByName("localhost"); - socket = new Socket(ip, port); + socket = new Socket(host, port); dis = new DataInputStream(socket.getInputStream()); dos = new DataOutputStream(socket.getOutputStream()); Thread th = new Thread(this::readMessages); diff --git a/src/main/java/com/boredxgames/tictactoeclient/presentation/GameController.java b/src/main/java/com/boredxgames/tictactoeclient/presentation/GameController.java index 8065a03..3c4dc7d 100644 --- a/src/main/java/com/boredxgames/tictactoeclient/presentation/GameController.java +++ b/src/main/java/com/boredxgames/tictactoeclient/presentation/GameController.java @@ -303,7 +303,7 @@ private void handleOfflinePve(int row, int col) { if (checkGameEnd()) { return; } - + updateTurnIndicator(); scheduleAiTurn(); } @@ -325,6 +325,7 @@ private void handleOnlinePvp(int row, int col) { private void performMove(int row, int col, char player) { gameBoard.makeMove(row, col, player); updateCell(row, col, player); + } private void scheduleAiTurn() { @@ -339,13 +340,12 @@ private void executeAiMove() { Move aiMove = gameService.getNextMove(gameBoard, GameBoard.PLAYER_O); if (aiMove != null) { - performMove(aiMove.getRow(), aiMove.getCol(), GameBoard.PLAYER_O); } if (!checkGameEnd()) { - enableBoard(); updateTurnIndicator(); + enableBoard(); } } @@ -378,21 +378,26 @@ private void updateCell(int row, int col, char player) { private void updateTurnIndicator() { char currentPlayer = gameBoard.getCurrentPlayer(); - - if (currentPlayer == GameBoard.PLAYER_X) { - setActiveCard(playerCard, opponentCard); - } - else { - setActiveCard(opponentCard, playerCard); - } - if (gameMode == GameMode.OFFLINE_PVP || gameMode == GameMode.OFFLINE_PVE || gameMode == GameMode.REPLAY) { - if (localPlayerId == GameBoard.PLAYER_X) { + + switch (gameMode) { + + case ONLINE_PVP -> { + if (currentPlayer == localPlayerId) { + setActiveCard(playerCard, opponentCard); + } else { + setActiveCard(opponentCard, playerCard); + } + } + + case OFFLINE_PVP, OFFLINE_PVE, REPLAY -> { + if (currentPlayer == GameBoard.PLAYER_X) { setActiveCard(playerCard, opponentCard); } else { setActiveCard(opponentCard, playerCard); } } } + } private void setActiveCard(VBox activeCard, VBox inactiveCard) { activeCard.getStyleClass().add("active-card"); diff --git a/src/main/java/com/boredxgames/tictactoeclient/presentation/Server_connectionController.java b/src/main/java/com/boredxgames/tictactoeclient/presentation/Server_connectionController.java index e4d88b0..51c118b 100644 --- a/src/main/java/com/boredxgames/tictactoeclient/presentation/Server_connectionController.java +++ b/src/main/java/com/boredxgames/tictactoeclient/presentation/Server_connectionController.java @@ -46,7 +46,7 @@ public void initialize(URL location, ResourceBundle resources) { }); serverPresets.put("Local Server", "127.0.0.1"); - serverPresets.put("Network Server", "192.168.1.3"); + serverPresets.put("Network Server", "10.145.0.124"); ipComboBox.getItems().addAll(serverPresets.keySet()); ipComboBox.getSelectionModel().select("Local Server");