diff --git a/recordings/REC_Player_vs_CPU_1768350437773.dat b/recordings/REC_Player_vs_CPU_1768350437773.dat new file mode 100644 index 0000000..885505a Binary files /dev/null and b/recordings/REC_Player_vs_CPU_1768350437773.dat differ 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");