From 29c241de55a441deb1ee431858910b001c173756 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Wed, 2 Feb 2022 15:17:15 +0100 Subject: [PATCH] 4gewinnt: updated mutltiple methods to deactivate buttons on full columns --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 10 ++++++++++ src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 1 + 2 files changed, 11 insertions(+) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 123202a..922f32f 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -66,12 +66,18 @@ public class Logic { int size = getBoardSize() - 1; while(getField(size, column) != 0) { size--; + if(size < 0) { + return -1; + } } return size; } public int playChip(int column) { setField(getCurrentPlayer(), getFreePlace(column), column); + if(getFreePlace(column) == -1) { + buttons[column].setEnabled(false); + } updateGui(); if(testForWin()) { gameover(); @@ -238,5 +244,9 @@ public class Logic { setPlayer2Score(calcScore()); } clearField(); + for(int i = 0; i < getBoardSize(); i++) { + buttons[i].setEnabled(true); + } + updateGui(); } } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 76ff279..3e27f5c 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -181,6 +181,7 @@ class LogicTest { @Test void gameoverTest() { testObj.setField(1, 0, 0); + testObj.create4gewinntGui(); testObj.gameover();