Exemple #1
0
 public Player getPreviousPlayer() {
   Player previous = null;
   Player last = null;
   for (Player player : players) {
     if (player.getNumber() > 0) {
       last = player;
       if (player.getNumber() < currentPlayerNumber) previous = player;
     }
   }
   return previous == null ? last : previous;
 }
Exemple #2
0
  @Override
  public Player addPlayer(String playerId, String playerName, int number) throws BoardException {
    int count = 0;
    for (Player player : players) if (player.getNumber() > 0) count++;
    if (number > 0 && roleNames.size() == count)
      throw new BoardException("This board has enough players.");

    RoleDO role = boardPackage.getRoles().get(roleNames.get(count).getName());
    PlayerRecordDO player =
        new PlayerRecordDO(this, role, playerId, playerName, number, makeElementRecords());

    players.add(player);
    if (number > 0) {
      executeAction(new PlayerJoinAction(player));
      if (roleNames.size() == count + 1) {
        executeAction(new BeginGameAction(this));
        executeAction(new BeginTurnAction(this, getCurrentPlayer()));
      }
    }
    return player;
  }
Exemple #3
0
 public Player getPlayer(int number) {
   for (Player player : players) if (player.getNumber() == number) return player;
   throw new IllegalArgumentException("Invalid player number " + number);
 }
Exemple #4
0
 public Player getNextPlayer() {
   for (Player player : players) if (player.getNumber() > currentPlayerNumber) return player;
   return players.get(0);
 }
Exemple #5
0
 public Player getCurrentPlayer() {
   for (Player player : players) if (player.getNumber() == currentPlayerNumber) return player;
   throw new IllegalStateException("Can not access current player " + currentPlayerNumber);
 }
Exemple #6
0
 public int getPlayerAmount() {
   int count = 0;
   for (Player player : players) if (player.getNumber() > 0) count++;
   return count;
 }