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 2b467bc + 3404690 commit b5e205e
Show file tree
Hide file tree
Showing 24 changed files with 183 additions and 168 deletions.
8 changes: 7 additions & 1 deletion src/main/java/it/unibo/common/api/road/RoadPosition.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.unibo.common.api.road;

import java.util.List;

import it.unibo.common.api.property.PropertyPosition;
import it.unibo.common.api.tile.TilePosition;

Expand All @@ -25,9 +27,13 @@ public interface RoadPosition {
boolean isNearby(RoadPosition other);

/**
*
* @param position
* @return true if this road is near the property in the given position.
*/
boolean isNearToProperty(PropertyPosition position);

/**
* @return the list of the positions nearby the current road
*/
List<PropertyPosition> getNearbyProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public boolean isNearby(final RoadPosition other) {

@Override
public boolean isNearToProperty(final PropertyPosition position) {
return getNearbyProperties().contains(position);
}

@Override
public List<PropertyPosition> getNearbyProperties() {
final List<PropertyPosition> nearRoadProperty = new ArrayList<>();
switch (getDirection()) {
case UPLEFT:
Expand Down Expand Up @@ -152,7 +157,7 @@ public boolean isNearToProperty(final PropertyPosition position) {
default:
break;
}
return nearRoadProperty.contains(position);
return nearRoadProperty;
}

}
55 changes: 0 additions & 55 deletions src/main/java/it/unibo/controller/api/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,7 @@ public interface BoardController {
PropertyType getPropertyType(PropertyPosition position);

/**
* Build a settlement in the given position.
*
* @param position where to build the settlement.
* @param playerName the player
*/
void buildSettlement(PropertyPosition position, String playerName);

/**
* Build a city in the given position.
*
* @param position where to build the city.
* @param playerName the player
*/
void buildCity(PropertyPosition position, String playerName);

/**
* Builds the road at position {@code position}.
*
* @param position position of the road
* @param playerName the player
*/
void buildRoad(RoadPosition position, String playerName);

/**
* @param player
* @return the longest road length of {@code player}
*/
int getLongestRoadLength(String playerName);
Expand All @@ -118,35 +94,4 @@ public interface BoardController {
* @param coordinates coordinates of the new robber's position
*/
void setRobberPosition(TilePosition coordinates);

/**
* @param position
* @return true if the property in the given position is near to an other
* property, false otherwise.
*/
boolean isNearToAnyProperty(PropertyPosition position);

/**
* @param playerName the player
* @param position
* @return true if the road in the given position is near to an other
* property of current player, false otherwise.
*/
boolean isRoadNearToAnyOwnedProperty(String playerName, RoadPosition position);

/**
* @param playerName the player
* @param position
* @return true if the property in the given position is near to an other
* road of current player, false otherwise.
*/
boolean isPropertyNearToAnyOwnerRoad(String playerName, PropertyPosition position);

/**
* @param playerName the player
* @param position
* @return true if the road in the given position is near to an other
* road of current player, false otherwise.
*/
boolean isRoadNearToAnyOwnedRoad(String playerName, RoadPosition position);
}
1 change: 0 additions & 1 deletion src/main/java/it/unibo/controller/api/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import it.unibo.common.api.property.PropertyPosition;
import it.unibo.common.api.road.RoadPosition;
import it.unibo.common.api.tile.ResourceType;
import it.unibo.model.api.Player;
import it.unibo.common.api.tile.TilePosition;

/**
Expand Down
54 changes: 4 additions & 50 deletions src/main/java/it/unibo/controller/impl/BoardControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public final class BoardControllerImpl implements BoardController {
/**
* Constructor of BoardControllerImpl.
*
* @param controller the main controller
* @param board the board to start with
* @param getPlayerByName the function to get the player by name
* @param board the board
* @param propertyManager the property manager
* @param roadManager the road manager
*/
public BoardControllerImpl(final Function<String, Player> getPlayerByName, final Board board,
final PropertyManager propertyManager, final RoadManager roadManager) {
Expand Down Expand Up @@ -90,26 +92,11 @@ public Set<RoadPosition> getAllRoadPositions() {
.collect(Collectors.toSet());
}

@Override
public void buildSettlement(final PropertyPosition position, final String playerName) {
this.propertyManager.addSettlement(position, getPlayerByName.apply(playerName));
}

@Override
public void buildCity(final PropertyPosition position, final String playerName) {
this.propertyManager.upgradeToCity(position);
}

@Override
public PropertyType getPropertyType(final PropertyPosition position) {
return this.propertyManager.getPropertyType(position);
}

@Override
public void buildRoad(final RoadPosition position, final String playerName) {
this.roadManager.addRoad(position, getPlayerByName.apply(playerName));
}

@Override
public int getLongestRoadLength(final String playerName) {
return this.roadManager.getLongestRoadLength(getPlayerByName.apply(playerName));
Expand All @@ -124,37 +111,4 @@ public TilePosition getRobberPosition() {
public void setRobberPosition(TilePosition coordinates) {
this.board.setRobberPosition(coordinates);
}

@Override
public boolean isNearToAnyProperty(final PropertyPosition position) {
return getAllPropertyPositions().stream().anyMatch(propertyPosition -> {
if (!getPropertyType(propertyPosition).equals(PropertyType.EMPTY)) {
return propertyPosition.isNear(position);
}
return false;
});
}

@Override
public boolean isRoadNearToAnyOwnedProperty(final String playerName, final RoadPosition position) {
return this.getPlayerPropertyPositions(playerName).stream()
.anyMatch(propertyPosition -> {
return position.isNearToProperty(propertyPosition.getKey());
});
}

@Override
public boolean isPropertyNearToAnyOwnerRoad(final String playerName, final PropertyPosition position) {
return this.getPlayerRoadPositions(playerName).stream()
.anyMatch(roadPosition -> {
return roadPosition.isNearToProperty(position);
});
}

@Override
public boolean isRoadNearToAnyOwnedRoad(final String playerName, final RoadPosition position) {
return this.getPlayerRoadPositions(playerName).stream().anyMatch(roadPosition -> {
return position.isNearby(roadPosition);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class MainControllerImpl implements MainController {
/**
* Constructor of the controller.
*
* @param appView the main view
* @param players list of players' names
*/
public MainControllerImpl(final AppView appView, final List<String> players) {
Expand Down Expand Up @@ -158,7 +159,7 @@ public boolean canEndTurn() {

@Override
public boolean canBuyCard() {
return this.gameManager.canBuyCard(turnController.getCurrentPlayerTurn());
return !mustPlaceRobber() && this.gameManager.canBuyCard(turnController.getCurrentPlayerTurn());
}

private Player getPlayerByName(final String name) {
Expand Down Expand Up @@ -201,7 +202,6 @@ public String getBank() {
return "bank";
}


@Override
public void setRobberPosition(TilePosition coordinates) {
this.boardController.setRobberPosition(coordinates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public final class ResourceControllerImpl implements ResourceController {
/**
* Constructor of resource controller.
*
* @param resourceManager
* @param bank
* @param getResourceOwnerByName the function to get the resource owner by name
* @param resourceManager the resource manager
*/
public ResourceControllerImpl(final Function<String, ResourceOwner> getResourceOwnerByName,
final ResourceManager resourceManager) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/it/unibo/model/api/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface GameManager {
* Build a settlement of player {@code player} at position {@code position}.
*
* @param position where to build the settlement.
* @param player the player who wants to build the settlement.
*/
void buildSettlement(PropertyPosition position, Player player);

Expand All @@ -35,12 +36,14 @@ public interface GameManager {
* Build a road of player {@code player} at position {@code position}.
*
* @param position where to build the road
* @param player the player who wants to build the road
*/
void buildRoad(RoadPosition position, Player player);

/**
* Player {@code player} buys a development card.
*
* @param player the player who wants to buy a card
*/
void buyCard(Player player);

Expand All @@ -53,8 +56,8 @@ public interface GameManager {
boolean canBuildSettlement(PropertyPosition position, Player player);

/**
* @param city
* @param position
* @param position where the city will be built
* @param player the player who wants to build the city
* @return whether player {@code player} can build a city at position
* {@code position}
*/
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/it/unibo/model/api/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
*/
public interface Player extends ResourceOwner {
/**
* Increment the victory points of the player.
* Increments the victory points of the player of {@code amount} points.
*
* @param amount
*/
void incrementVictoryPoints(int amount);

/**
* Decrements the victory points of the player of {@code amount} points.
*
* @param amount
*/
void incrementVictoryPoints();
void decrementVictoryPoints(int amount);

/**
* Get the victory points of the player.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/it/unibo/model/api/PropertyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public interface PropertyManager {
Set<Property> getPlayerProperties(Player player);

/**
* @param player
* Get all the properties built by the specified players.
*
* @param players
* @return a set of the properties built by every player.
*/
Set<Property> getAllPlayersProperties(List<Player> players);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/it/unibo/model/api/RoadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface RoadManager {
* @param position the position of the road
* @param player the player who owns the road
*/
void addRoad(RoadPosition position, Player player);
void buildRoad(RoadPosition position, Player player);

/**
* @param player
Expand All @@ -25,8 +25,14 @@ public interface RoadManager {

/**
* @param player
* @return the length of the longest road owned by {@code player}
* @return the length of the longest road (without cycles) owned by
* {@code player}
*/
int getLongestRoadLength(Player player);

/**
* @return the player owning the longest road
*/
Player getLongestRoadOwner();

}
8 changes: 7 additions & 1 deletion src/main/java/it/unibo/model/impl/DevelopmentCardsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
import it.unibo.common.api.card.CardType;
import it.unibo.model.api.DevelopmentCards;

public class DevelopmentCardsImpl implements DevelopmentCards {
/**
* Development cards implementation.
*/
public final class DevelopmentCardsImpl implements DevelopmentCards {
private final List<CardType> deck = new ArrayList<>();
private final Random random = new Random();

/**
* Constructor of DevelopmentCardsImpl.
*/
public DevelopmentCardsImpl() {
final int knightCards = 15;
final int roadBuildCards = 5;
Expand Down
Loading

0 comments on commit b5e205e

Please sign in to comment.