コード例 #1
0
ファイル: Game.java プロジェクト: dallinca/Settlers
 /**
  * The art of placing a settlement on the vertex.
  *
  * @pre the Can do is true
  * @param vertexLocation
  * @throws Exception
  * @post a settlement is placed on a vertex
  */
 public void placeSettlementOnVertex(int UserId, VertexLocation vertexLocation) throws Exception {
   if (canDoPlaceSettlementOnVertex(UserId, vertexLocation) == false) {
     throw new Exception(
         "Cannot build Settlement on this vertex, this should not have been allowed to get this far.");
   }
   // If we are in the first two rounds of the game
   if (turnNumber < 2) {
     board.placeInitialSettlementOnVertex(currentPlayer, vertexLocation);
     versionNumber++;
     // Here we collect the resources for the second placed settlement in setup round
     if (turnNumber == 1) {
       Hex[] adjacentHexes = board.getVertex(vertexLocation).getAdjacentHexes();
       for (Hex hex : adjacentHexes) {
         if (hex != null) {
           ResourceType hexResourceType = hex.getHexResourceType();
           ResourceCard card = bank.playerTakeResource(hexResourceType);
           currentPlayer.getResourceCardHand().addCard(card);
         }
       }
     }
   } else {
     board.placeSettlementOnVertex(currentPlayer, vertexLocation);
     versionNumber++;
   }
 }
コード例 #2
0
ファイル: Game.java プロジェクト: dallinca/Settlers
  /**
   * This method does the actual trade by interacting with the bank and the Current Player to
   * ascertain the port type and what if they can trade or not.
   *
   * @pre the resource types it receives are valid, and that tradeIn is what the player performing
   *     the trade already has
   * @throws Exception
   */
  public void doMaritimeTrade(ResourceType tradeIn, ResourceType receive) throws Exception {

    if (canDoPlayerDoMaritimeTrade(tradeIn, receive)) {

      ResourceCard[] tradingCards = currentPlayer.prepareBankTrade(tradeIn);

      bank.playerTurnInResources(tradingCards);

      currentPlayer.getResourceCardHand().addCard(bank.playerTakeResource(receive));

    } else throw new Exception("Cannot do Maritime Trade");
  }
コード例 #3
0
ファイル: Game.java プロジェクト: dallinca/Settlers
  /**
   * 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();
  }