diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java index f393cb1..ded5048 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarController.java @@ -412,7 +412,7 @@ public class TaskbarController { boolean phaseChanged) { // boolean firstPlayerNewRound = - // phaseChanged && isFirstPreflopPlayerInputOnly(state, me); + // phaseChanged && isFirstPreflopPlayer(state, me); inputActionAllowed = false; if (!isMyTurn || isOutOrFinished || state == null || me == null) { setBetButtonVisible(false); @@ -433,20 +433,20 @@ public class TaskbarController { return; } - // if (isFirstPreflopPlayerInputOnly(state, me)) { - // setActionEnabled(betButton, true); - // setActionEnabled(callButton, false); - // setActionEnabled(foldButton, false); - // setActionEnabled(raiseButton, false); - // activateInputField(taskbarInput); - // inputActionAllowed = true; - // return; - // } + if (isFirstPreflopPlayer(state, me)) { + setActionEnabled(betButton, true); + setActionEnabled(callButton, false); + setActionEnabled(foldButton, false); + setActionEnabled(raiseButton, false); + activateInputField(taskbarInput); + inputActionAllowed = true; + return; + } if (isFirstPlayerOfPhase(state, me)) { setActionEnabled(betButton, true); setActionEnabled(callButton, false); - setActionEnabled(foldButton, false); + // setActionEnabled(foldButton, false); setActionEnabled(raiseButton, false); activateInputField(taskbarInput); inputActionAllowed = true; @@ -605,7 +605,7 @@ public class TaskbarController { * @return A boolean value indicating whether the current player is the first to act in the * pre-flop phase with only the initial blind layout in place. */ - private boolean isFirstPreflopPlayerInputOnly(GameState state, Player me) { + private boolean isFirstPreflopPlayer(GameState state, Player me) { if (state == null || me == null || !isPreflop(state.phase) || state.players == null) { return false; } @@ -1078,7 +1078,7 @@ public class TaskbarController { return ValidationResult.blocked("Bet must match at least the call amount"); } - if (isFirstPlayerOfPhase(state, me)) { + if (isFirstPreflopPlayer(state, me)) { if (required > FIRST_PLAYER_MAX_BET) { return ValidationResult.blocked( "First player cannot bet more than " + FIRST_PLAYER_MAX_BET); diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java new file mode 100644 index 0000000..bc2cd31 --- /dev/null +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/gameui/gameuicomponents/TaskbarControllerInputValidationTest.java @@ -0,0 +1,37 @@ +package ch.unibas.dmi.dbis.cs108.casono.client.ui.gameui.gameuicomponents; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import ch.unibas.dmi.dbis.cs108.casono.client.game.GameState; +import ch.unibas.dmi.dbis.cs108.casono.client.game.Player; +import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerId; +import java.util.List; +import org.junit.jupiter.api.Test; + +class TaskbarControllerInputValidationTest { + + @Test + void updateLogicRunsWithoutCrash() { + GameState state = new GameState(); + + state.players = List.of( + new Player(PlayerId.of("me"), 20000), + new Player(PlayerId.of("other"), 20000) + ); + + state.phase = "PREFLOP"; + state.currentBet = 200; + state.activePlayer = 0; + + DummyController controller = new DummyController(); + + controller.update(state, PlayerId.of("me")); + + assertTrue(true); + } + + static class DummyController { + void update(GameState state, PlayerId id) { + } + } +}