/** * This method polls the player to see if the player can build a road and then returns the result * to that which called it (most likely the client) * * @return a true or false to if the player can build a road there. */ public boolean canDoPlayerBuildRoad(int UserId) { if (!isPlayersTurn(UserId)) { return false; } if (turnNumber == 0) { if (currentPlayer.getNumberUnplayedRoads() != 15) { return false; } return true; } else if (turnNumber == 1) { if (currentPlayer.getNumberUnplayedRoads() != 14) { return false; } return true; } else { return currentPlayer.canDoBuyRoad(); } }
/** * 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); } }
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++; } }