Exemplo n.º 1
0
  public int playRound(Player player, DiceValue pick, int bet) {
    if (player == null) throw new IllegalArgumentException("Player cannot be null.");
    if (pick == null) throw new IllegalArgumentException("Pick cannot be negative.");
    if (bet < 0) throw new IllegalArgumentException("Bet cannot be negative.");

    int matches = 0;
    for (Dice d : dice) {
      d.roll();
      if (d.getValue().equals(pick)) {
        matches += 1;
      }
    }

    int winnings = matches * bet;

    if (matches > 0) {
      player.receiveWinnings(winnings);
    } else {
      player.takeBet(bet);
    }
    return winnings;
  }