From 1a0cfdc0f0b2ef0a875ad32d388875cbfae29930 Mon Sep 17 00:00:00 2001 From: davi-bart Date: Fri, 16 Feb 2024 16:06:15 +0100 Subject: [PATCH 1/2] fix typos --- .../it/unibo/controller/main/MainController.java | 6 +++--- .../java/it/unibo/model/property/Property.java | 2 +- .../unibo/model/property/PropertyManagerImpl.java | 12 ++++++------ .../unibo/model/resource/ResourceManagerImpl.java | 14 +++++++------- src/main/java/it/unibo/view/BoardView.java | 2 +- src/main/java/it/unibo/view/CurrentPlayerView.java | 2 +- src/main/java/it/unibo/view/Menu.java | 2 +- .../java/it/unibo/view/ResourcesViewFactory.java | 3 +-- src/main/java/it/unibo/view/Utility.java | 8 ++++---- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/java/it/unibo/controller/main/MainController.java b/src/main/java/it/unibo/controller/main/MainController.java index c3a8705..b8bb437 100644 --- a/src/main/java/it/unibo/controller/main/MainController.java +++ b/src/main/java/it/unibo/controller/main/MainController.java @@ -58,13 +58,13 @@ public interface MainController { void buildRoad(RoadPosition position); /** - * The current player buys a developement card. + * The current player buys a development card. */ void buyCard(); /** * @return whether the current player can build a settlement - * @param position where to build the settlemet + * @param position where to build the settlement */ boolean canBuildSettlement(PropertyPosition position); @@ -81,7 +81,7 @@ public interface MainController { boolean canBuildRoad(RoadPosition position); /** - * @return whether the current player can buy a developement card. + * @return whether the current player can buy a development card. */ boolean canBuyCard(); diff --git a/src/main/java/it/unibo/model/property/Property.java b/src/main/java/it/unibo/model/property/Property.java index 2704112..6168d23 100644 --- a/src/main/java/it/unibo/model/property/Property.java +++ b/src/main/java/it/unibo/model/property/Property.java @@ -25,7 +25,7 @@ public interface Property { PropertyType getPropertyType(); /** - * Upgrade a settlemet to city. + * Upgrade a settlement to city. */ void upgrade(); } diff --git a/src/main/java/it/unibo/model/property/PropertyManagerImpl.java b/src/main/java/it/unibo/model/property/PropertyManagerImpl.java index d0a5687..984f1e9 100644 --- a/src/main/java/it/unibo/model/property/PropertyManagerImpl.java +++ b/src/main/java/it/unibo/model/property/PropertyManagerImpl.java @@ -15,24 +15,24 @@ * Property manager implementation. */ public final class PropertyManagerImpl implements PropertyManager { - private final Set properies = new LinkedHashSet<>(); + private final Set properties = new LinkedHashSet<>(); @Override public void addSettlement(final PropertyPosition position, final Player player) { - if (properies.stream().anyMatch(r -> r.getPosition().equals(position))) { + if (properties.stream().anyMatch(r -> r.getPosition().equals(position))) { throw new IllegalArgumentException("Settlement was already present"); } - properies.add(new PropertyImpl(position, player)); + properties.add(new PropertyImpl(position, player)); } @Override public Set getPlayerProperties(final Player player) { - return properies.stream().filter(r -> r.getOwner().equals(player)).collect(Collectors.toSet()); + return properties.stream().filter(r -> r.getOwner().equals(player)).collect(Collectors.toSet()); } @Override public void upgradeToCity(final PropertyPosition position) { - final Optional property = properies.stream().filter(p -> p.getPosition().equals(position)) + final Optional property = properties.stream().filter(p -> p.getPosition().equals(position)) .findFirst(); if (property.isPresent()) { property.get().upgrade(); @@ -41,7 +41,7 @@ public void upgradeToCity(final PropertyPosition position) { @Override public PropertyType getPropertyType(final PropertyPosition position) { - return properies.stream().filter(p -> p.getPosition().equals(position)) + return properties.stream().filter(p -> p.getPosition().equals(position)) .findFirst().map(p -> p.getPropertyType()).orElse(PropertyType.EMPTY); } diff --git a/src/main/java/it/unibo/model/resource/ResourceManagerImpl.java b/src/main/java/it/unibo/model/resource/ResourceManagerImpl.java index 8887a0c..953f0f9 100644 --- a/src/main/java/it/unibo/model/resource/ResourceManagerImpl.java +++ b/src/main/java/it/unibo/model/resource/ResourceManagerImpl.java @@ -84,26 +84,26 @@ public Map getResources(final ResourceOwner owner) { @Override public boolean canTrade(final ResourceOwner proposer, final ResourceOwner accepter, - final Map proposedResouces, + final Map proposedResources, final Map wantedResources) { /** * */ - initializeResourceMap(proposedResouces); + initializeResourceMap(proposedResources); initializeResourceMap(wantedResources); - if (proposedResouces.values().stream().allMatch(amount -> amount == 0) + if (proposedResources.values().stream().allMatch(amount -> amount == 0) && wantedResources.values().stream().allMatch(amount -> amount == 0)) { return false; } - if (!(hasResources(proposer, proposedResouces) && hasResources(accepter, wantedResources))) { + if (!(hasResources(proposer, proposedResources) && hasResources(accepter, wantedResources))) { return false; } if (accepter.equals(bank)) { - return proposedResouces.values().stream().anyMatch(amount -> amount == 4) - && proposedResouces.values().stream().mapToInt(i -> i).sum() == 4 + return proposedResources.values().stream().anyMatch(amount -> amount == 4) + && proposedResources.values().stream().mapToInt(i -> i).sum() == 4 && wantedResources.values().stream().mapToInt(i -> i).sum() == 1; } - return !(proposedResouces.values().stream().allMatch(amount -> amount == 0) + return !(proposedResources.values().stream().allMatch(amount -> amount == 0) || wantedResources.values().stream().allMatch(amount -> amount == 0)); } diff --git a/src/main/java/it/unibo/view/BoardView.java b/src/main/java/it/unibo/view/BoardView.java index c3e100f..04bd619 100644 --- a/src/main/java/it/unibo/view/BoardView.java +++ b/src/main/java/it/unibo/view/BoardView.java @@ -30,7 +30,7 @@ public BoardView(final MainController controller, final Map playe this.controller = controller; this.playerColors = playerColors; - // add the exagons and properties/road to the board + // add the hexagons and properties/road to the board final Group group = new Group(); drawTiles(); group.getChildren().addAll(this.tiles.values()); diff --git a/src/main/java/it/unibo/view/CurrentPlayerView.java b/src/main/java/it/unibo/view/CurrentPlayerView.java index 0cb2b7a..7e05c28 100644 --- a/src/main/java/it/unibo/view/CurrentPlayerView.java +++ b/src/main/java/it/unibo/view/CurrentPlayerView.java @@ -107,7 +107,7 @@ private Button getRollButton() { } private Button getBuyCardButton() { - final Button buyCardButton = new Button("Buy developement card"); + final Button buyCardButton = new Button("Buy development card"); buyCardButton.setOnAction(e -> { if (controller.canBuyCard()) { controller.buyCard(); diff --git a/src/main/java/it/unibo/view/Menu.java b/src/main/java/it/unibo/view/Menu.java index e4dfdd4..4d3c99e 100644 --- a/src/main/java/it/unibo/view/Menu.java +++ b/src/main/java/it/unibo/view/Menu.java @@ -107,7 +107,7 @@ public Scene getScene() throws IOException { stage.close(); new AppViewImpl(stage, players).draw(); } else { - popUp.setHeaderText("You need atleast one player to start the game"); + popUp.setHeaderText("You need at least one player to start the game"); popUp.showAndWait(); } diff --git a/src/main/java/it/unibo/view/ResourcesViewFactory.java b/src/main/java/it/unibo/view/ResourcesViewFactory.java index 3d8d549..161e1d2 100644 --- a/src/main/java/it/unibo/view/ResourcesViewFactory.java +++ b/src/main/java/it/unibo/view/ResourcesViewFactory.java @@ -57,12 +57,11 @@ public static VBox getResourceLabelAmount(final ResourceType resource, final int } /** - * * @param resource resource type. * @param amount amount of resource. * @param listener action to perform on change. * @return the image view of the needed resource with a combobox representing - * the amout. + * the amount. */ public static VBox resourceAndComboBox(final ResourceType resource, final int amount, final ChangeListener listener) { diff --git a/src/main/java/it/unibo/view/Utility.java b/src/main/java/it/unibo/view/Utility.java index c6cd21a..2796b4b 100644 --- a/src/main/java/it/unibo/view/Utility.java +++ b/src/main/java/it/unibo/view/Utility.java @@ -61,14 +61,14 @@ public static Pair, Pair> getRoadCoordinate } /** - * returns the coordinates of the propertiy of an hexagon in the specified + * Calculates the coordinates of the property of an hexagon in the specified * direction. * - * @param radius radius + * @param radius radius of the hexagon * @param x x coordinate of the center * @param y y coordinate of the center * @param direction direction of the property - * @return a map of properties, by their direction + * @return the coordinates of the property, in pixels */ public static Pair getPropertyCoordinates(final double radius, final double x, final double y, final PropertyDirection direction) { @@ -78,7 +78,7 @@ public static Pair getPropertyCoordinates(final double radius, f } /** - * returns the position of a tile in the board. + * Calculates the position of a tile in the board. * * @param row row * @param col column From 5622cda0332d56b47b76893a0f57a3945926f7b3 Mon Sep 17 00:00:00 2001 From: davi-bart Date: Fri, 16 Feb 2024 16:23:10 +0100 Subject: [PATCH 2/2] remove unused function + make function private --- .../controller/board/BoardController.java | 18 ------------------ .../controller/board/BoardControllerImpl.java | 16 ---------------- .../unibo/controller/main/MainController.java | 12 ------------ .../controller/main/MainControllerImpl.java | 8 ++++++-- .../resource/ResourceController.java | 9 --------- .../resource/ResourceControllerImpl.java | 5 ----- src/main/java/it/unibo/view/RobberView.java | 3 +-- 7 files changed, 7 insertions(+), 64 deletions(-) diff --git a/src/main/java/it/unibo/controller/board/BoardController.java b/src/main/java/it/unibo/controller/board/BoardController.java index 100af1e..12355b3 100644 --- a/src/main/java/it/unibo/controller/board/BoardController.java +++ b/src/main/java/it/unibo/controller/board/BoardController.java @@ -3,8 +3,6 @@ import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; - import it.unibo.common.property.PropertyPosition; import it.unibo.common.property.PropertyType; import it.unibo.common.road.RoadPosition; @@ -38,22 +36,6 @@ public interface BoardController { */ TerrainType getTileTerrainType(TilePosition pos); - /** - * get the player's road positions. - * - * @param playerName the player - * @return the set of the road positions - */ - Set getPlayerRoadPositions(String playerName); - - /** - * get the player's property positions. - * - * @param playerName the player - * @return the set of the property positions and their types - */ - Set> getPlayerPropertyPositions(String playerName); - /** * get all the road positions, including empty ones. * diff --git a/src/main/java/it/unibo/controller/board/BoardControllerImpl.java b/src/main/java/it/unibo/controller/board/BoardControllerImpl.java index f0c8327..bd9d2ee 100644 --- a/src/main/java/it/unibo/controller/board/BoardControllerImpl.java +++ b/src/main/java/it/unibo/controller/board/BoardControllerImpl.java @@ -6,9 +6,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; - import it.unibo.common.property.PropertyDirection; import it.unibo.common.property.PropertyPosition; import it.unibo.common.property.PropertyPositionImpl; @@ -63,19 +60,6 @@ public TerrainType getTileTerrainType(final TilePosition pos) { return this.board.getTileTerrainType(pos); } - @Override - public Set getPlayerRoadPositions(final String playerName) { - return this.roadManager.getPlayerRoads(getPlayerByName.apply(playerName)).stream().map(r -> r.getPosition()) - .collect(Collectors.toSet()); - } - - @Override - public Set> getPlayerPropertyPositions(final String playerName) { - return this.propertyManager.getPlayerProperties(getPlayerByName.apply(playerName)).stream() - .map(p -> new ImmutablePair(p.getPosition(), p.getPropertyType())) - .collect(Collectors.toSet()); - } - @Override public Set getAllPropertyPositions() { return getTilePositions().stream() diff --git a/src/main/java/it/unibo/controller/main/MainController.java b/src/main/java/it/unibo/controller/main/MainController.java index b8bb437..a1ddf00 100644 --- a/src/main/java/it/unibo/controller/main/MainController.java +++ b/src/main/java/it/unibo/controller/main/MainController.java @@ -26,11 +26,6 @@ public interface MainController { */ ResourceController getResourceController(); - // /** - // * @return the turn controller - // */ - // TurnController getTurnController(); - /** * @return the list of the players' names */ @@ -114,13 +109,6 @@ public interface MainController { */ boolean canRollDie(); - /** - * give the resources produced by the tile with the given number. - * - * @param rollSum sum of the 2 dices. - */ - void produceResources(int rollSum); - /** * Modify the resources of the owners into the trade. * diff --git a/src/main/java/it/unibo/controller/main/MainControllerImpl.java b/src/main/java/it/unibo/controller/main/MainControllerImpl.java index f5b4566..242684d 100644 --- a/src/main/java/it/unibo/controller/main/MainControllerImpl.java +++ b/src/main/java/it/unibo/controller/main/MainControllerImpl.java @@ -144,8 +144,12 @@ public boolean canRollDie() { return !turnController.hasRolled() && turnController.getCycle() > 2; // } - @Override - public void produceResources(final int number) { + /** + * give the resources produced by the tiles with the given number. + * + * @param rollSum sum of the 2 dices. + */ + private void produceResources(final int number) { final Map> producedResources = gameManager.produceResources(number); producedResources.forEach((player, resources) -> { resources.entrySet().stream().filter(entry -> entry.getValue() > 0) diff --git a/src/main/java/it/unibo/controller/resource/ResourceController.java b/src/main/java/it/unibo/controller/resource/ResourceController.java index 9e9f7d8..7d0b60a 100644 --- a/src/main/java/it/unibo/controller/resource/ResourceController.java +++ b/src/main/java/it/unibo/controller/resource/ResourceController.java @@ -19,15 +19,6 @@ public interface ResourceController { */ Map getBankResources(); - /** - * * Return if the given owner has the given resources. - * - * @param owner owner - * @param resources - * @return true if the given owner has the given resources, false otherwise - */ - boolean hasResources(String owner, Map resources); - /** * Modify the resources of the players into the trade. * diff --git a/src/main/java/it/unibo/controller/resource/ResourceControllerImpl.java b/src/main/java/it/unibo/controller/resource/ResourceControllerImpl.java index 6ad23a4..715f928 100644 --- a/src/main/java/it/unibo/controller/resource/ResourceControllerImpl.java +++ b/src/main/java/it/unibo/controller/resource/ResourceControllerImpl.java @@ -37,11 +37,6 @@ public Map getPlayerResources(final String owner) { return out; } - @Override - public boolean hasResources(final String owner, final Map resource) { - return resourceManager.hasResources(getPlayerByName.apply(owner), resource); - } - @Override public Map getBankResources() { return resourceManager.getResources(resourceManager.getBank()); diff --git a/src/main/java/it/unibo/view/RobberView.java b/src/main/java/it/unibo/view/RobberView.java index 3c6fcec..355cb3b 100644 --- a/src/main/java/it/unibo/view/RobberView.java +++ b/src/main/java/it/unibo/view/RobberView.java @@ -82,8 +82,7 @@ private void showDiscardStage(final String player) { discardContainer.getChildren().add(resourcesContainer); discardContainer.getChildren().add(confirm); - final Scene stageScene = new Scene(discardContainer, 500, - 300); + final Scene stageScene = new Scene(discardContainer, 500, 300); stage.initModality(Modality.APPLICATION_MODAL); stage.setScene(stageScene); stage.setResizable(false);