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;
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();
}
}

1
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();

Loading…
Cancel
Save