Exemple #1
0
 /**
  * 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);
 }
Exemple #2
0
 /**
  * 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++;
   }
 }
Exemple #3
0
 /**
  * TODO - Verify Completion
  *
  * <p>Places a Road for the specified player at specified edgeLocation
  *
  * @pre canDoPlaceRoadOnEdge != false
  * @param UserId
  * @throws Exception
  * @return Void
  */
 public void placeRoadOnEdge(int UserId, EdgeLocation edgeLocation) 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 (turnNumber < 2) {
     board.placeInitialRoadOnEdge(getCurrentPlayer(), edgeLocation);
     versionNumber++;
   } else {
     board.placeRoadOnEdge(getCurrentPlayer(), edgeLocation);
   }
 }
Exemple #4
0
 /**
  * Retrieves whether the Robber can be moved to the specified hexLocation
  *
  * @pre board != null
  * @param hex
  * @return whether the Robber can be moved to the specified hexLocation
  */
 public boolean canDoMoveRobberToHex(int UserId, HexLocation hexLocation) {
   // Check if the user is the current player
   if (UserId != currentPlayer.getPlayerId()) {
     return false;
   }
   return board.canDoMoveRobberToHex(hexLocation);
 }
Exemple #5
0
 /**
  * Can we place a settlement on that vertex?
  *
  * @pre the vertex location is not null
  * @param vertexLocation
  * @post it tells you whether or not you can build a Settlement on that vertex
  */
 public boolean canDoPlaceSettlementOnVertex(int UserId, VertexLocation vertexLocation) {
   // Check if the user is the current player
   if (UserId != currentPlayer.getPlayerId()) {
     return false;
   }
   return board.canDoPlaceSettlementOnVertex(currentPlayer, vertexLocation);
 }
Exemple #6
0
 /**
  * Places the beautiful city on it's designated spot.
  *
  * @pre the Can do is true
  * @param vertexLocation
  * @throws Exception
  * @post a city is placed on a vertex
  */
 public void placeCityOnVertex(VertexLocation vertexLocation) throws Exception {
   if (canDoPlaceCityOnVertex(vertexLocation)) {
     board.placeCityOnVertex(currentPlayer, vertexLocation);
     versionNumber++;
     versionNumber++;
   } else
     throw new Exception(
         "Cannot build City on this vertex, this should not have been allowed to get this far.");
 }
Exemple #7
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++;
   }
 }
Exemple #8
0
 /**
  * TODO - Verify Completion
  *
  * <p>Checks to see if the given Player can place a road on the specified edge
  *
  * @pre None
  * @param UserId
  * @param edgeLocation
  * @return whether the Specified player can place a road on the specified edge
  */
 public boolean canDoPlaceRoadOnEdge(int UserId, EdgeLocation edgeLocation) {
   // Check if the user is the current player
   if (UserId != currentPlayer.getPlayerId()) {
     System.out.println("Game1: false");
     return false;
   }
   // If we are in the setup phase, the rules for placing a road are slightly different
   if (turnNumber == 0) {
     if (currentPlayer.getNumberUnplayedRoads() != 15) {
       return false;
     }
     return board.canDoPlaceInitialRoadOnEdge(getCurrentPlayer(), edgeLocation);
   } else if (turnNumber == 1) {
     if (currentPlayer.getNumberUnplayedRoads() != 14) {
       return false;
     }
     return board.canDoPlaceInitialRoadOnEdge(getCurrentPlayer(), edgeLocation);
   } else {
     return board.canDoPlaceRoadOnEdge(getCurrentPlayer(), edgeLocation);
   }
 }
Exemple #9
0
 /**
  * This is only intended for extracting information from the hexes for the map initialization
  *
  * @pre None
  * @return PortType[][]
  */
 public PortType[] getMapPorts() {
   return board.getMapPorts();
 }
Exemple #10
0
 /**
  * This is only intended for extracting information from the hexes for the map initialization
  *
  * @pre None
  * @return Hex[][]
  */
 public Hex[][] getMapHexes() {
   return board.getMapHexes();
 }
Exemple #11
0
 /**
  * This method ensures we can place a city on the given vertex
  *
  * @pre the vertex location is not null
  * @param vertexLocation
  * @post it tells you whether or not you can build a Settlement on that vertex
  */
 public boolean canDoPlaceCityOnVertex(VertexLocation vertexLocation) {
   return board.canDoPlaceCityOnVertex(currentPlayer, vertexLocation);
 }