Exemplo n.º 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;
 }
Exemplo n.º 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;
  }
Exemplo n.º 3
0
 public Player getPlayer(int number) {
   for (Player player : players) if (player.getNumber() == number) return player;
   throw new IllegalArgumentException("Invalid player number " + number);
 }
Exemplo n.º 4
0
 public Player getNextPlayer() {
   for (Player player : players) if (player.getNumber() > currentPlayerNumber) return player;
   return players.get(0);
 }
Exemplo n.º 5
0
 public Player getCurrentPlayer() {
   for (Player player : players) if (player.getNumber() == currentPlayerNumber) return player;
   throw new IllegalStateException("Can not access current player " + currentPlayerNumber);
 }
Exemplo n.º 6
0
 public int getPlayerAmount() {
   int count = 0;
   for (Player player : players) if (player.getNumber() > 0) count++;
   return count;
 }