From e684a87d66335b9cdf1ce814f8721d1fca056ca6 Mon Sep 17 00:00:00 2001 From: kfkama Date: Tue, 15 Feb 2022 12:49:03 +0100 Subject: [PATCH] Expanded cell click logic --- src/main/java/TicTacToe/cell.java | 22 +++++++++++-------- .../java/TicTacToe/TicTacToeGameTest.java | 2 -- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/TicTacToe/cell.java b/src/main/java/TicTacToe/cell.java index b8c4351..65e0db5 100644 --- a/src/main/java/TicTacToe/cell.java +++ b/src/main/java/TicTacToe/cell.java @@ -22,15 +22,19 @@ public class cell extends JButton { } protected void OnMouseClick() { - value = ttt.player; - ttt.endTurn(); - switch (value) { - case 1: setBackground(new Color(255,0,0)); - break; - case 2: setBackground(new Color(0,0,255)); - break; - default: ; - break; + if(value == 0) { + value = ttt.player; + ttt.endTurn(); + setEnabled(false); + + switch (value) { + case 1: setBackground(new Color(255,0,0)); + break; + case 2: setBackground(new Color(0,0,255)); + break; + default: ; + break; + } } } diff --git a/src/test/java/TicTacToe/TicTacToeGameTest.java b/src/test/java/TicTacToe/TicTacToeGameTest.java index 08742dd..a02accb 100644 --- a/src/test/java/TicTacToe/TicTacToeGameTest.java +++ b/src/test/java/TicTacToe/TicTacToeGameTest.java @@ -4,7 +4,5 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class TicTacToeGameTest { - - }