Пример #1
0
  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) ;
    }
  }