Online-TicTacToe

Log | Files | Refs | README | LICENSE

commit 5af209d44f15174ce4dcbe55b7c0fe9251eaa10f
parent cd7d3dae4b01ff361c8cf2d0a23e145c4556503f
Author: adglas21 <adamglasheen99@gmail.com>
Date:   Thu, 28 Nov 2024 17:01:09 +0000

Forfeit button implemented

Diffstat:
MTicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/MainContentPanel.java | 35++++++++++++++++++-----------------
MTicTacToeClient/src/main/java/com/groupproject/tictactoeclient/PollingThread.java | 30++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 17 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 @@ -171,23 +171,24 @@ public class MainContentPanel extends CustomPanel { }); -// //forfeit button action listener -// forfeitButton.addActionListener(e -> { -// if(client.UID.equals(client.HOST_UID)) -// { -// client.proxy.setGameState(Integer.parseInt(client.GID), 2); -// -// -// } -// else -// { -// client.proxy.setGameState(Integer.parseInt(client.GID), 1); -// } -// -// -// refresh(); // refresh the list to show if there is a new game added -// }); -// + //forfeit button action listener + forfeitButton.addActionListener(e -> { + if(client.UID.equals(client.HOST_UID)) + { + client.proxy.setGameState(Integer.parseInt(client.GID), 2); + + } + else + { + client.proxy.setGameState(Integer.parseInt(client.GID), 1); + } + + client.resetGame(); + client.showPanel(new MainContentPanel(client)); + refresh(); + + }); + scoreButton.addActionListener(e -> { diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/PollingThread.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/PollingThread.java @@ -91,6 +91,36 @@ public class PollingThread implements Runnable { JOptionPane.showMessageDialog(client.frame, "Error checking the game status."); } + + + //call the web server to check if the game has been won or not yet if the player is forfeiting + String gameState = client.proxy.getGameState(Integer.parseInt(client.GID)); + switch (gameState) { + + + case "1": + // Player 1 wins + JOptionPane.showMessageDialog(client.frame, "The other player has forfeited, you win"); + + helperMethods.showOptions(); + gameOver = true; + break; + case "2": + // Player 2 wins + JOptionPane.showMessageDialog(client.frame, "The other player has forfeited, you win"); + + helperMethods.showOptions(); + gameOver = true; + break; + case "3": + // Player 2 wins + JOptionPane.showMessageDialog(client.frame, "It's a draw!"); + + helperMethods.showOptions(); + gameOver = true; + break; + } + //} } catch (Exception e) {