From f507b533775c1ed5ffcf316b6327ebf925bbe71c Mon Sep 17 00:00:00 2001
From: JimmyTheCat <154287729+JimmyTheCatOwO@users.noreply.github.com>
Date: Thu, 9 Jan 2025 16:41:47 +0100
Subject: [PATCH] GameUI clean up multiple board calls and ifs to one board
 call and switch

---
 GameUI.java | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/GameUI.java b/GameUI.java
index 058350c..f852ffc 100644
--- a/GameUI.java
+++ b/GameUI.java
@@ -151,22 +151,26 @@ public class GameUI extends Application{
 
         buttons[index].setGraphic(imageView);
         
-        board.turnEnd();
-        updatePlayerTurn(board.currentPlayer);
-
-        //changes label state for the winning player and updates its score
-        if (board.victoryCheck()) {
-            winnerLabel.setText("Player " + (board.currentPlayer == 0 ? "X" : "O") + " wins!");
-            updatePlayerScore();
-            stage.setScene(winningScene);
-            return; 
-        } 
+        switch (board.turnEnd()) {
+            case 0:
+                updatePlayerTurn(board.currentPlayer);
+                break;
         
-        //changes label state to draw
-        if (board.marks == 9) {
-            winnerLabel.setText("It's a draw!");
-            stage.setScene(winningScene);
-            return; 
+            case 1:
+                //changes label state for the winning player and updates its score
+                winnerLabel.setText("Player " + (board.currentPlayer == 0 ? "X" : "O") + " wins!");
+                updatePlayerScore();
+                stage.setScene(winningScene);
+                break;
+            
+            case 2:
+                //changes label state to draw
+                winnerLabel.setText("It's a draw!");
+                stage.setScene(winningScene);
+                break;
+            default:
+                System.out.println("How did we get here?");
+                break;
         }
     }
 
-- 
GitLab