Example #1
0
  /**
   * This method Uses a development card and marks it as played
   *
   * @param devCardType is valid and you own that card
   * @return whether or not you just won the game
   * @throws Exception
   */
  public boolean useMonumentCard(int userID, DevCardType devCardType) throws Exception {
    if (currentPlayer.getPlayerId() == userID) {

      if (currentPlayer.canDoPlayDevelopmentCard(turnNumber, devCardType)) {
        // Marks the card as played
        currentPlayer.playDevelopmentCard(turnNumber, devCardType);
        currentPlayer.setHasPlayedDevCardThisTurn(true);

        // Now do what monuments do:
        currentPlayer.incrementVictoryPoints();
        setVersionNumber(versionNumber++);
        return doWeHaveAWinner();
      } else throw new Exception("Cannot Play Monument card!");
    } else throw new Exception("Cannot Play Monument card, you are not the current Player!");
  }
Example #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();
  }