Skip to content

Commit

Permalink
Merge branch 'main' of github.com:davi-bart/OOP23-coloni-ces
Browse files Browse the repository at this point in the history
  • Loading branch information
andsam0 committed Feb 16, 2024
2 parents 427da3f + 5622cda commit db47c79
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 90 deletions.
18 changes: 0 additions & 18 deletions src/main/java/it/unibo/controller/board/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<RoadPosition> getPlayerRoadPositions(String playerName);

/**
* get the player's property positions.
*
* @param playerName the player
* @return the set of the property positions and their types
*/
Set<Pair<PropertyPosition, PropertyType>> getPlayerPropertyPositions(String playerName);

/**
* get all the road positions, including empty ones.
*
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/it/unibo/controller/board/BoardControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,19 +60,6 @@ public TerrainType getTileTerrainType(final TilePosition pos) {
return this.board.getTileTerrainType(pos);
}

@Override
public Set<RoadPosition> getPlayerRoadPositions(final String playerName) {
return this.roadManager.getPlayerRoads(getPlayerByName.apply(playerName)).stream().map(r -> r.getPosition())
.collect(Collectors.toSet());
}

@Override
public Set<Pair<PropertyPosition, PropertyType>> getPlayerPropertyPositions(final String playerName) {
return this.propertyManager.getPlayerProperties(getPlayerByName.apply(playerName)).stream()
.map(p -> new ImmutablePair<PropertyPosition, PropertyType>(p.getPosition(), p.getPropertyType()))
.collect(Collectors.toSet());
}

@Override
public Set<PropertyPosition> getAllPropertyPositions() {
return getTilePositions().stream()
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/it/unibo/controller/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public interface MainController {
*/
ResourceController getResourceController();

// /**
// * @return the turn controller
// */
// TurnController getTurnController();

/**
* @return the list of the players' names
*/
Expand Down Expand Up @@ -58,13 +53,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);

Expand All @@ -81,7 +76,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();

Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player, Map<ResourceType, Integer>> producedResources = gameManager.produceResources(number);
producedResources.forEach((player, resources) -> {
resources.entrySet().stream().filter(entry -> entry.getValue() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ public interface ResourceController {
*/
Map<ResourceType, Integer> 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<ResourceType, Integer> resources);

/**
* Modify the resources of the players into the trade.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public Map<ResourceType, Integer> getPlayerResources(final String owner) {
return out;
}

@Override
public boolean hasResources(final String owner, final Map<ResourceType, Integer> resource) {
return resourceManager.hasResources(getPlayerByName.apply(owner), resource);
}

@Override
public Map<ResourceType, Integer> getBankResources() {
return resourceManager.getResources(resourceManager.getBank());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/model/property/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface Property {
PropertyType getPropertyType();

/**
* Upgrade a settlemet to city.
* Upgrade a settlement to city.
*/
void upgrade();
}
12 changes: 6 additions & 6 deletions src/main/java/it/unibo/model/property/PropertyManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
* Property manager implementation.
*/
public final class PropertyManagerImpl implements PropertyManager {
private final Set<Property> properies = new LinkedHashSet<>();
private final Set<Property> 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<Property> 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> property = properies.stream().filter(p -> p.getPosition().equals(position))
final Optional<Property> property = properties.stream().filter(p -> p.getPosition().equals(position))
.findFirst();
if (property.isPresent()) {
property.get().upgrade();
Expand All @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/it/unibo/model/resource/ResourceManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ public Map<ResourceType, Integer> getResources(final ResourceOwner owner) {

@Override
public boolean canTrade(final ResourceOwner proposer, final ResourceOwner accepter,
final Map<ResourceType, Integer> proposedResouces,
final Map<ResourceType, Integer> proposedResources,
final Map<ResourceType, Integer> 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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/view/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BoardView(final MainController controller, final Map<String, Color> 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());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/view/CurrentPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/view/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/it/unibo/view/ResourcesViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> listener) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/it/unibo/view/RobberView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/it/unibo/view/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public static Pair<Pair<Double, Double>, Pair<Double, Double>> 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<Double, Double> getPropertyCoordinates(final double radius, final double x,
final double y, final PropertyDirection direction) {
Expand All @@ -78,7 +78,7 @@ public static Pair<Double, Double> 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
Expand Down

0 comments on commit db47c79

Please sign in to comment.