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 15, 2024
2 parents 48c7dc0 + ac62826 commit d302601
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public TilePosition getRobberPosition() {
}

@Override
public void setRobberPosition(TilePosition coordinates) {
public void setRobberPosition(final TilePosition coordinates) {
this.board.setRobberPosition(coordinates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public String getBank() {
}

@Override
public void setRobberPosition(TilePosition coordinates) {
public void setRobberPosition(final TilePosition coordinates) {
this.boardController.setRobberPosition(coordinates);
this.mustPlaceRobber = false;
this.appView.redrawCurrentPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void acceptTrade(final String proposer, final String accepter,
}

@Override
public Map<ResourceType, Integer> getResources(String owner) {
public Map<ResourceType, Integer> getResources(final String owner) {
return resourceManager.getResources(getResourceOwnerByName.apply(owner));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/it/unibo/model/impl/DevelopmentCardsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public DevelopmentCardsImpl() {
@Override
public CardType getCard() {
if (!isDeckEmpty()) {
int index = random.nextInt(deck.size());
CardType pulledCard = deck.get(index);
final int index = random.nextInt(deck.size());
final CardType pulledCard = deck.get(index);
deck.remove(index);
return pulledCard;
} else {
Expand All @@ -51,7 +51,7 @@ public CardType getCard() {

@Override
public boolean isDeckEmpty() {
return deck.size() == 0;
return deck.isEmpty();
}

}
4 changes: 1 addition & 3 deletions src/main/java/it/unibo/model/impl/GameManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ public void buyCard(final Player player) {
.forEach((resource, amount) -> resourceManager.removeResources(player, resource, amount));
if (developmentCards.getCard().equals(CardType.VICTORYPOINT)) {
turnManager.getCurrentPlayerTurn().incrementVictoryPoints(1);
System.out.println(turnManager.getCurrentPlayerTurn().getVictoryPoints());
}

}

@Override
public boolean canBuildSettlement(final PropertyPosition position, final Player player) {
final int cycle = turnManager.getCycle();
System.out.println(cycle);
if (cycle <= 2) {
return !isPropertyNearToAnyProperty(position)
&& propertyManager.getPlayerProperties(player).size() < cycle;
Expand All @@ -170,7 +168,7 @@ public boolean canBuildCity(final PropertyPosition position, final Player player
return false;
}
return this.propertyManager.getPlayerProperties(player).stream().map(property -> property.getPosition())
.anyMatch(propertyPosition -> position.equals(position))
.anyMatch(propertyPosition -> propertyPosition.equals(position))
&& this.resourceManager.hasResources(player, Recipes.getCityResources());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/model/impl/PropertyManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PropertyType getPropertyType(final PropertyPosition position) {

@Override
public Set<Property> getAllPlayersProperties(final List<Player> players) {
Set<Property> out = new HashSet<>();
final Set<Property> out = new HashSet<>();
players.forEach(player -> {
getPlayerProperties(player).forEach(property -> out.add(property));
});
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/it/unibo/model/impl/ResourceManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ResourceManagerImpl(final List<Player> players, final int bankResourcesAm
}

@Override
public final void addResources(final ResourceOwner owner, final ResourceType resource, final int amount) {
public void addResources(final ResourceOwner owner, final ResourceType resource, final int amount) {
if (amount >= 0) {
allEntityResources.get(owner).compute(resource, (k, v) -> v + amount);
} else {
Expand All @@ -41,7 +41,7 @@ public final void addResources(final ResourceOwner owner, final ResourceType res
}

@Override
public final void removeResources(final ResourceOwner owner, final ResourceType resource, final int amount) {
public void removeResources(final ResourceOwner owner, final ResourceType resource, final int amount) {
if (allEntityResources.get(owner).get(resource) >= amount) {
allEntityResources.get(owner).compute(resource, (k, v) -> v - amount);
} else {
Expand All @@ -50,12 +50,12 @@ public final void removeResources(final ResourceOwner owner, final ResourceType
}

@Override
public final int getResource(final ResourceOwner owner, final ResourceType resource) {
public int getResource(final ResourceOwner owner, final ResourceType resource) {
return allEntityResources.get(owner).get(resource);
}

@Override
public final void acceptTrade(final ResourceOwner proposer, final ResourceOwner accepter,
public void acceptTrade(final ResourceOwner proposer, final ResourceOwner accepter,
final Map<ResourceType, Integer> givingResouces,
final Map<ResourceType, Integer> recivingResources) {

Expand All @@ -71,7 +71,7 @@ public final void acceptTrade(final ResourceOwner proposer, final ResourceOwner
}

@Override
public final boolean hasResources(final ResourceOwner owner, final Map<ResourceType, Integer> resources) {
public boolean hasResources(final ResourceOwner owner, final Map<ResourceType, Integer> resources) {
for (final Entry<ResourceType, Integer> resource : resources.entrySet()) {
if (resource.getValue() > getResource(owner, resource.getKey())) {
return false;
Expand All @@ -86,7 +86,7 @@ public ResourceOwner getBank() {
}

@Override
public Map<ResourceType, Integer> getResources(ResourceOwner owner) {
public Map<ResourceType, Integer> getResources(final ResourceOwner owner) {
return allEntityResources.get(owner);
}
}
1 change: 0 additions & 1 deletion src/main/java/it/unibo/model/impl/RoadManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public Player getLongestRoadOwner() {
private void checkLongestRoad(final Player player) {
final int minimumLongestRoadLength = 5;
final int longestRoadVictoryPoints = 2;
System.out.println(getLongestRoadLength(player));
if ((!longestRoadOwnerExists() && getLongestRoadLength(player) >= minimumLongestRoadLength)
|| (longestRoadOwnerExists() && !player.equals(longestRoadOwner)
&& getLongestRoadLength(player) > getLongestRoadLength(longestRoadOwner))) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/it/unibo/model/impl/TurnManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
public final class TurnManagerImpl implements TurnManager {

private boolean hasRolled = false;
private int turnNumber = 0;
private boolean hasRolled;
private int turnNumber;
private int currentTurn;
private final Iterator<Integer> iterator;
private final List<Player> playerList = new ArrayList<>();
Expand Down Expand Up @@ -77,7 +77,7 @@ public int getTurnNumber() {

@Override
public int getCycle() {
return (turnNumber / playerList.size()) + 1;
return turnNumber / playerList.size() + 1;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/it/unibo/view/AppViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class AppViewImpl implements AppView {
* Constructor of AppView.
*
* @param stage the stage
* @param players the list of players names
*/
public AppViewImpl(final Stage stage, final List<String> players) {

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 @@ -52,7 +52,7 @@ private void drawTiles() {
});
}

private void redrawTile(TilePosition coords) {
private void redrawTile(final TilePosition coords) {
this.tiles.get(coords).draw();
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/it/unibo/view/CurrentPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public CurrentPlayerView(final MainController controller) {
*/
public void draw() {
super.getChildren().clear();

// controller.getPlayerResources(controller.getCurrentPlayer()).entrySet().forEach(entry
// -> super.getChildren()
// .add(ResourcesViewFactory.getResourceLabelAmount(entry.getKey(),
// entry.getValue())));
drawResources();

super.getChildren().add(tradeView.getTradeButton());
Expand Down Expand Up @@ -77,7 +72,7 @@ private Button getRollButton() {
final Button rollButton = new Button("Roll die");
rollButton.setOnAction(e -> {
if (controller.canRollDie()) {
var roll = controller.rollDie();
final var roll = controller.rollDie();
rolledValue.setText("Rolled value: " + (roll.getLeft() + roll.getRight()) + "(" + roll.getLeft() + ","
+ roll.getRight() + ")");
rollButton.setText(String.valueOf(roll.getLeft() + roll.getRight()));
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/it/unibo/view/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ public void draw() throws IOException {
stage.show();
}

private void addPlayer(final int size, final ObservableList<String> list, final TextField textfield, final Alert alert) {
private void addPlayer(final int size, final ObservableList<String> list, final TextField textfield,
final Alert alert) {
if (size < 4) {
if (list.contains(textfield.getText()) || textfield.getText().equals("bank")) {
if (list.contains(textfield.getText()) || "bank".equals(textfield.getText())) {
alert.setHeaderText("You cannot choose this name");
alert.showAndWait();
} else {
if (textfield.getText().equals("")) {
if ("".equals(textfield.getText())) {
alert.setHeaderText("An empty text field is not a valid name");
alert.showAndWait();
} else {
Expand Down Expand Up @@ -88,9 +89,9 @@ public Scene getScene() throws IOException {
final Button addButton = new Button("ADD PLAYER");
final Scene scene = new Scene(root);
final TextField textField = new TextField();
final TableView<String> tableView = new TableView<String>();
final TableView<String> tableView = new TableView<>();
final Alert popUp = new Alert(AlertType.ERROR);
final TableColumn<String, String> playerName = new TableColumn<String, String>("Player Name");
final TableColumn<String, String> playerName = new TableColumn<>("Player Name");
final int maxTableHeight = 140;
final int maxTableWidth = 300;
final int minTableHeight = 0;
Expand Down Expand Up @@ -120,16 +121,16 @@ public Scene getScene() throws IOException {
});

textField.setOnKeyPressed(e -> {
if (e.getCode() == (KeyCode.ENTER)) {
if (e.getCode() == KeyCode.ENTER) {
addPlayer(players.size(), players, textField, popUp);
}
});

Image image = new Image("imgs/menu/SettlersOfCesena.png");
BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, true);
BackgroundImage backgroundImage = new BackgroundImage(image, BackgroundRepeat.NO_REPEAT,
final Image image = new Image("imgs/menu/SettlersOfCesena.png");
final BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, true);
final BackgroundImage backgroundImage = new BackgroundImage(image, BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize);
Background background = new Background(backgroundImage);
final Background background = new Background(backgroundImage);

tableView.setItems(players);
playerName.prefWidthProperty().bind(tableView.widthProperty());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/it/unibo/view/PlayersView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public PlayersView(final MainController controller, final Map<String, Color> pla

/**
* Draw the players view.
*
* @param playerColors the colors of the players
*/
public void draw(final Map<String, Color> playerColors) {
super.getChildren().clear();
controller.getPlayerNames().forEach(playerName -> {
Label playerInfo = new Label(playerName + ": " + controller.getPlayerPoints(playerName)
final Label playerInfo = new Label(playerName + ": " + controller.getPlayerPoints(playerName)
+ " points, longest road length: " + controller
.getBoardController().getLongestRoadLength(playerName));
playerInfo.setTextFill(playerColors.get(playerName));
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/it/unibo/view/RobberView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
* RobberView.
*/
public final class RobberView {
private final MainController controller;
private int sum;
Expand All @@ -33,9 +36,8 @@ public RobberView(final MainController controller) {
}

/**
* Get the trade button.
*
* @return the trade button
* Evoke the robber.
* Test function.
*/
public void evokeRobber() {
if (controller.mustPlaceRobber()) {
Expand Down Expand Up @@ -76,7 +78,6 @@ private void showRobberStage(final String player) {
(options, oldValue, newValue) -> {
discardResources.put(resource, newValue);
reloadConfirmButton.run();
System.out.println(discardResources);
}));
});
reloadConfirmButton.run();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/it/unibo/view/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* View of a tile.
* Consists of the hexagon and the nearby roads and properties.
*/
public class TileView extends Group {
public final class TileView extends Group {
static final int SIDES = 6;
private final MainController controller;
private final TilePosition coordinates;
Expand Down Expand Up @@ -56,8 +56,7 @@ public void draw() {
final double x = pos.getLeft();
final double y = pos.getRight();
final Polygon hexagon = getHexagon(Utility.HEXAGON_RADIUS, x, y);
Image img = new Image("imgs/hexes/" + terrainType.toString().toLowerCase(Locale.US) + ".png");
hexagon.setFill(new ImagePattern(img));
hexagon.setFill(new ImagePattern(new Image("imgs/hexes/" + terrainType.toString().toLowerCase(Locale.US) + ".png")));
hexagon.setOnMouseClicked(eventHandler);
super.getChildren().add(hexagon);
if (terrainType != TerrainType.DESERT) {
Expand Down

0 comments on commit d302601

Please sign in to comment.