Browse Source

4gewinnt: updated mutltiple methods to deactivate buttons on full columns

4gewinnt
Steffen Helmke 3 years ago
committed by Lorenz Hohmann
parent
commit
29c241de55
  1. 10
      src/main/java/de/tims/viergewinnt/ai/Logic.java
  2. 1
      src/test/java/de/tims/viergewinnt/ai/LogicTest.java

10
src/main/java/de/tims/viergewinnt/ai/Logic.java

@ -66,12 +66,18 @@ public class Logic {
int size = getBoardSize() - 1; int size = getBoardSize() - 1;
while(getField(size, column) != 0) { while(getField(size, column) != 0) {
size--; size--;
if(size < 0) {
return -1;
}
} }
return size; return size;
} }
public int playChip(int column) { public int playChip(int column) {
setField(getCurrentPlayer(), getFreePlace(column), column); setField(getCurrentPlayer(), getFreePlace(column), column);
if(getFreePlace(column) == -1) {
buttons[column].setEnabled(false);
}
updateGui(); updateGui();
if(testForWin()) { if(testForWin()) {
gameover(); gameover();
@ -238,5 +244,9 @@ public class Logic {
setPlayer2Score(calcScore()); setPlayer2Score(calcScore());
} }
clearField(); clearField();
for(int i = 0; i < getBoardSize(); i++) {
buttons[i].setEnabled(true);
}
updateGui();
} }
} }

1
src/test/java/de/tims/viergewinnt/ai/LogicTest.java

@ -181,6 +181,7 @@ class LogicTest {
@Test @Test
void gameoverTest() { void gameoverTest() {
testObj.setField(1, 0, 0); testObj.setField(1, 0, 0);
testObj.create4gewinntGui();
testObj.gameover(); testObj.gameover();

Loading…
Cancel
Save