commit 77124e5061e7ca9931051f3902c09635ce9eef64 parent 9be7706785c56850c528a1ef9dcd83883e2d6027 Author: William Lindholm <william_lindholm@outlook.com> Date: Wed, 27 Nov 2024 16:43:19 +0000 Fixed bug regarding who gets next turn Diffstat:
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java @@ -16,6 +16,7 @@ public class MainContentPanel extends CustomPanel { private int remainingTime; private TicTacToeGrid grid; private JLabel userNameLabel; + private JLabel gameStatusLabel; public MainContentPanel(TicTacToeClient client) { this.client = client; @@ -34,7 +35,7 @@ public class MainContentPanel extends CustomPanel { openGamesList = new JList<>(); JScrollPane openGamesScrollPane = new JScrollPane(openGamesList); grid = new TicTacToeGrid(client, 3, 3); // A 3x3 TicTacToe grid - JLabel gameStatusLabel = new JLabel(); + gameStatusLabel = new JLabel(); gameTimerLabel = new JLabel(); userNameLabel = new JLabel(); JButton scoreButton = new JButton("View Personal Score"); @@ -121,6 +122,7 @@ public class MainContentPanel extends CustomPanel { if (client.GID != null && !client.GID.isEmpty()) { client.HOST_UID = client.UID; + client.OPPONENTS_TURN = false; String newGameData = "Game " + client.GID + " Host: " + client.UID; if (client.openGames == null || client.openGames.isEmpty()) { client.openGames = newGameData; @@ -160,6 +162,12 @@ public class MainContentPanel extends CustomPanel { // System.out.println("Raw client.openGames data: " + client.openGames); // Debugging output grid.refresh(); + + if (client.OPPONENTS_TURN) { + gameStatusLabel.setText("Opponents turn!"); + } else { + gameStatusLabel.setText("Your turn!"); + } // Check if openGames is empty/null, if there is nothin then display nothing in the box if (client.openGames == null || client.openGames.isEmpty()) { diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/TicTacToeGrid.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/TicTacToeGrid.java @@ -64,16 +64,18 @@ public class TicTacToeGrid extends JPanel { } public void refresh() { - System.out.println("UID: " + client.UID + ", HOST_UID: " + client.HOST_UID + ", GAME_ID: " + client.GID + ", MOVES: " + client.NUM_OF_MOVES); + System.out.println("UID: " + client.UID + ", HOST_UID: " + client.HOST_UID + ", GAME_ID: " + client.GID + ", MOVES: " + client.NUM_OF_MOVES + ", ISHOST: " + helperMethods.IsHost()); if (client.BOARD == null) { return; } final int[][] board = client.BOARD; client.NUM_OF_MOVES = client.BOARD.length; + if (client.NUM_OF_MOVES % 2 == 0 && helperMethods.IsHost()) { client.OPPONENTS_TURN = false; } + if (client.NUM_OF_MOVES % 2 == 1 && !helperMethods.IsHost()) { client.OPPONENTS_TURN = false; } diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/TicTacToeClient.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/TicTacToeClient.java @@ -29,7 +29,7 @@ public class TicTacToeClient { private CustomPanel CurrentPanel; public String UID = ""; public String GID = ""; - public boolean OPPONENTS_TURN = false; + public boolean OPPONENTS_TURN = true; public int NUM_OF_MOVES = 0; public String UID2; public String GID_Temp;