commit 9dc0fbb285cb7ff6132f4806a2acb9c4a5be33b7
parent 1f560590e2c1159ae4fb9aaa3dba8454a01d14d9
Author: lukeeeeeee334 <lukeosullivan123@gmail.com>
Date: Thu, 28 Nov 2024 17:09:16 +0000
merge
Diffstat:
3 files changed, 75 insertions(+), 19 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
@@ -163,23 +163,48 @@ 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);
+ }
+
+
+ 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 -> {
client.showPanel(new score(client));
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) {
diff --git a/TicTacToeWS/src/main/java/com/tttws/TicTacToeWS.java b/TicTacToeWS/src/main/java/com/tttws/TicTacToeWS.java
@@ -14,7 +14,7 @@ import jakarta.jws.soap.SOAPBinding;
/**
*
- * @author adam
+ * @author petar
*/
@WebService(serviceName = "TicTacToeWebService")
@@ -370,6 +370,8 @@ public class TicTacToeWS {
try {
String result = dao.retrieve(sqlCmd);
if(result.equals("1")) {
+ sqlCmd = "DELETE FROM moves WHERE gID = " + gid + ";"; // delete moves first
+ result = dao.remove(sqlCmd); // run the SQL statement
sqlCmd = "DELETE FROM games WHERE autokey = " + gid + ";";
result = dao.remove(sqlCmd);
return "1";
@@ -389,7 +391,6 @@ public class TicTacToeWS {
*/
@WebMethod(operationName = "showMyOpenGames")
public String showMyOpenGames(@WebParam(name = "uid") int uid) {
- System.out.println("Called showMyOpenGames()");
String sqlCmd = "SELECT g.autokey, u.username, g.started FROM games g, users u WHERE g.p1 = " + uid + " AND g.p2 IS NULL AND g.p1 = u.autokey ORDER BY g.started ASC;";
try {
String result = dao.retrieve(sqlCmd);