Esempio n. 1
0
 /**
  * This method stands to show if the player CAN use one of his/her un-used dev Cards of the type
  * you ask it about.
  *
  * @param devCardType
  * @return
  */
 public boolean canDoPlayerUseDevelopmentCard(int userID, DevCardType devCardType) {
   // We need to be able to measure how long a player has owned a card.
   if (currentPlayer.getPlayerId() == userID) {
     return currentPlayer.canDoPlayDevelopmentCard(turnNumber, devCardType);
   }
   return false;
 }
Esempio n. 2
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!");
  }
Esempio n. 3
0
 /**
  * This card is special because it is the only development card that references the bank, so
  * additional checks need to be made, and so for security reasons it gets its own method to do so.
  */
 public boolean canDoPlayerUseYearOfPlenty(ResourceType[] resourceType, int userID) {
   // This is important because the bank not have the cards they need.
   if (currentPlayer.getPlayerId() == userID) {
     if (resourceType.length == 1) {
       if (!canDoPlayerTake2OfResource(resourceType[0])) {
         return false;
       }
     } else {
       for (int i = 0; i < resourceType.length; i++) {
         if (!bank.canDoPlayerTakeResource(resourceType[i])) return false;
       }
     }
     return currentPlayer.canDoPlayDevelopmentCard(turnNumber, DevCardType.YEAR_OF_PLENTY);
   }
   return false;
 }
Esempio n. 4
0
 public void placeRoadOnEdge(int userId, EdgeLocation edgeLocation, boolean usingRoadBuilder)
     throws Exception {
   if (canDoPlaceRoadOnEdge(userId, edgeLocation) == false) {
     throw new Exception("Specified Player cannot place a road on the given edgeLocation");
   }
   // If we are in the setup phase, the rules for placing a road are slightly different
   if (usingRoadBuilder == true) {
     if (currentPlayer.getPlayerId() == userId
         && currentPlayer.canDoPlayDevelopmentCard(turnNumber, DevCardType.ROAD_BUILD)
         && currentPlayer.getNumberUnplayedRoads() >= 2) {
       board.placeRoadBuildRoadOnEdge(getCurrentPlayer(), edgeLocation);
       versionNumber++;
     } else {
       throw new Exception("Unable to play Road Builder!");
     }
   } else {
     board.placeRoadOnEdge(getCurrentPlayer(), edgeLocation);
     versionNumber++;
   }
 }
Esempio n. 5
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();
  }
Esempio n. 6
0
  /**
   * TODO Javadoc and Implement
   *
   * @param devCardType
   * @param resourceType
   * @return
   * @throws Exception
   */
  public boolean useDevelopmentCard(
      int userID, DevCardType devCardType, ResourceType[] resourceType) throws Exception {

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

      if (currentPlayer.canDoPlayDevelopmentCard(turnNumber, devCardType)) {
        switch (devCardType) {
          case MONOPOLY:
            if (resourceType == null || resourceType.length > 1) {
              throw new Exception("Trying to use monopoly on more than one resource!");
            }
            // Declare a Resource the player wants, and then extract it from all players who have
            // it.
            for (int i = 0; i < players.length; i++) {
              if (players[i] != currentPlayer) {
                // If not the current player, ask the player for an Array list of it's resource card
                // of that type
                currentPlayer
                    .conformToMonopoly(resourceType[0])
                    .addAll(players[i].conformToMonopoly(resourceType[0]));
                players[i].conformToMonopoly(resourceType[0]).clear();
              }
            }
            currentPlayer.playDevelopmentCard(turnNumber, DevCardType.MONOPOLY);
            currentPlayer.setHasPlayedDevCardThisTurn(true);
            setVersionNumber(versionNumber++);
            return doWeHaveAWinner();
          case YEAR_OF_PLENTY:
            if (canDoPlayerUseYearOfPlenty(resourceType, userID)) {
              // Add two resources of the types specified to the currentPlayers hand
              if (resourceType.length == 1) {
                ResourceCard resource = bank.playerTakeResource(resourceType[0]);
                // some sneaky idea that realizes conformToMonopoly returns the arraylist of that
                // players cards of a specified type.
                currentPlayer.conformToMonopoly(resourceType[0]).add(resource);
                ;
                // repeat
                resource = bank.playerTakeResource(resource.getResourceType());
                currentPlayer.conformToMonopoly(resourceType[0]).add(resource);
              } else if (resourceType.length == 2) {
                for (int g = 0; g < resourceType.length; g++) {
                  ResourceCard resource = bank.playerTakeResource(resourceType[g]);
                  // some sneaky idea that realizes conformToMonopoly returns the arraylist of that
                  // players cards of a specified type.
                  currentPlayer.conformToMonopoly(resourceType[g]).add(resource);
                }
              }
              currentPlayer.playDevelopmentCard(turnNumber, DevCardType.YEAR_OF_PLENTY);
              currentPlayer.setHasPlayedDevCardThisTurn(true);
              setVersionNumber(versionNumber++);
              return doWeHaveAWinner();
            } else {
              throw new Exception("The bank has not what you seek.");
            }
          default:
            throw new Exception("Wrong declaration for a development card of this type.");
        }
      }
    } else {
      throw new Exception("You cannot use a development Card");
    }

    return doWeHaveAWinner();
  }