Пример #1
0
 public int getNumberOfSoldiersPlayed(int userID) {
   Player player = getPlayerByID(userID);
   if (player == null) {
     return -1;
   }
   return player.getNumberOfSoldiersPlayed();
 }
Пример #2
0
  public boolean useSoldierCard(int userID, PlaySoldier_Params params) {
    // Do they have more than three soldiers? Do they have the most soldiers? If so, award them the
    // Largest Army award (assuming they don't already have it) and take it from the previous title
    // holder
    // Must move robber to a different hex

    if (currentPlayer.getPlayerId() == userID) {

      if (currentPlayer.canDoPlayDevelopmentCard(turnNumber, DevCardType.SOLDIER)) {
        if (canDoStealPlayerResource(userID, params.getVictimIndex())) {

          try {
            moveRobberToHex(userID, params.getLocation());
            stealPlayerResource(userID, params.getVictimIndex());
            currentPlayer.playDevelopmentCard(turnNumber, DevCardType.SOLDIER);
            currentPlayer.setHasPlayedDevCardThisTurn(true);
          } catch (Exception e) {
            System.out.println(
                "Something went wrong when trying to move the robber or steal resources");
            e.printStackTrace();
          }

          boolean firstTime = true;

          // Initial selection of LargestArmy recipient.
          if (currentPlayer.getNumberOfSoldiersPlayed() == 3) {
            for (int i = 0; i < players.length; i++) {
              if (players[i].getPlayerId() != currentPlayer.getPlayerId()
                  && players[i].getNumberOfSoldiersPlayed() >= 3) {
                firstTime = false;
              }
            }
            if (firstTime) {
              indexOfLargestArmy = currentPlayer.getPlayerIndex();
              largestArmy = currentPlayer;
              currentPlayer.incrementVictoryPoints();
              currentPlayer.incrementVictoryPoints();
            }
          }
          int test = 0;
          // Check for competition
          if (currentPlayer.getNumberOfSoldiersPlayed() >= 3 && !firstTime) {
            if (currentPlayer.getNumberOfSoldiersPlayed() > largestArmy.getNumberOfSoldiersPlayed()
                && currentPlayer.getPlayerId() != largestArmy.getPlayerId()) {
              // indexOfLargestArmy = currentPlayer.getPlayerId();

              for (int i = 0; i < players.length; i++) {
                if (largestArmy.getPlayerId() == players[i].getPlayerId()) {
                  players[i].decrementVictoryPoints();
                  players[i].decrementVictoryPoints();
                }
              }

              largestArmy = currentPlayer;
              currentPlayer.incrementVictoryPoints();
              currentPlayer.incrementVictoryPoints();
            }
          }
          // Did the Largest Army award win the game?!
          setVersionNumber(versionNumber++);
          return doWeHaveAWinner();
        }
      }
    }
    return doWeHaveAWinner();
  }