/** Rolls 2 dice and returns the sum */ public int roll() { int a = (int) (Math.random() * sides + 1); int b = (int) (Math.random() * sides + 1); GUI.setDice(a, b); value = a + b; return value; }
// 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. } }