예제 #1
0
파일: Game.java 프로젝트: dallinca/Settlers
 /**
  * Moves the robber to the specified HexLocation, and retrieves the players that own municipals
  * next to that hex, excluding those that don't have resources to steal and the player that moved
  * the robber
  *
  * @pre canDoMoveRobberToHex != null
  * @param hex
  * @throws Exception
  * @return array of Players that are adjacent to the new Robber Hex, that have resources to steal.
  */
 public Player[] moveRobberToHex(int UserId, HexLocation hexLocation) throws Exception {
   if (canDoMoveRobberToHex(UserId, hexLocation) == false) {
     throw new Exception("Cannot move Robber to that Hex");
   }
   board.moveRobberToHex(hexLocation);
   Hex hex = board.getHex(hexLocation);
   Vertex[] adjacentVertices = hex.getAdjacentVertices();
   ArrayList<Integer> adjacentPlayerIDs = new ArrayList<Integer>();
   ArrayList<Player> adjacentPlayers = new ArrayList<Player>();
   for (Vertex vertex : adjacentVertices) {
     // If the vertex has a municipal, that municipal is not owned by the player moving the robber
     // and the Player is not already in the list, and the Player has resources to be stolen
     if (vertex.getMunicipal() != null) {
       int municipalID = vertex.getMunicipal().getPlayer().getPlayerIndex();
       Player player = vertex.getMunicipal().getPlayer();
       if (vertex.hasMunicipal()
           && UserId != municipalID
           && !adjacentPlayerIDs.contains(municipalID)
           && player.getResourceCardHandSize() > 0) {
         adjacentPlayerIDs.add(municipalID);
         adjacentPlayers.add(player);
       }
     }
   }
   // Convert the found players into an array to return
   Player[] players = new Player[adjacentPlayers.size()];
   return adjacentPlayers.toArray(players);
 }
예제 #2
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++;
   }
 }