public void advanceGame() { if (mainButtonState != GAME_OVER_STATE) { if (amountNotBroke() == 1) { mainButtonState = GAME_OVER_STATE; } if (currentPlayer.isBroke()) { // Prints when a player looses String[] options1 = {"Deal with it."}; int nrOfOptions = 1; String[] options = new String[nrOfOptions]; for (int i = 0; i < options.length; i++) { options[i] = options1[i]; } String message = getCurentPlayer().getName() + ", you have lost"; while ((gui.getUserButtonPressed(options, message, "You have lost the game")) == -1) ; } if (mainButtonState == ROLL_STATE) { boolean playerBroke = moveController.playerTurn(currentPlayer); if (!playerBroke) playerBroke = fieldController.LandOnField(currentPlayer, currentPlayer.getPosition()); currentPlayer.setBroke(playerBroke); if (!dice.isTwoOfAKind() || currentPlayer.isBroke() || currentPlayer.isInPrisson()) mainButtonState = END_TURN_STATE; } // This runs when the player end his turn else if (mainButtonState == END_TURN_STATE) { if (!currentPlayer.isBroke()) { // add player back to the queue playerQueue.add(currentPlayer); } // pick next player from the queue currentPlayer = playerQueue.remove(); currentPlayer.setTwoOfAKindRollCount(0); mainButtonState = ROLL_STATE; } } if (mainButtonState == GAME_OVER_STATE) { // You have won message. String[] options1 = {"Proceed"}; int nrOfOptions = 1; String[] options = new String[nrOfOptions]; for (int i = 0; i < options.length; i++) { options[i] = options1[i]; } String message = getWinner().getName() + ", you have won! Contragratulations"; while ((gui.getUserButtonPressed(options, message, "You have won the game")) == -1) ; } }
// Method for the player turn - The player can only use the turn if their balance is not 0 private void playerTurn(Player player) { if (player.getAccount().getBalance() != 0) { GUI.showMessage(player.getName() + Text.roll); // The player is asked to roll the dice GUI.removeCar( player.getPosition(), player.getName()); // car is removed from previous position player.addPosition(dicecup.roll()); // Dice is rolled, and the players position is saved GUI.setDice( dicecup.getDie1().getLastRoll(), dicecup.getDie2().getLastRoll()); // Dice is shown on screen GUI.setCar(player.getPosition(), player.getName()); // Car is moved to field landedOnField(player); // Runs the operation for the field the player landed on GUI.setBalance( player.getName(), player.getAccount().getBalance()); // Shows current player balance on GUI game board if (player.getAccount().getBalance() == 0) bankRupt( player); // Player is removed from the game if their balance is 0, after their turn. } }