Skip to content

Commit

Permalink
add getRoadOwner method
Browse files Browse the repository at this point in the history
  • Loading branch information
davi-bart committed Feb 16, 2024
1 parent 904c3eb commit cc7552d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/it/unibo/controller/board/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public interface BoardController {
* @return the name of the owner of the property at the given position
*/
Optional<String> getPropertyOwner(PropertyPosition position);

/**
* @param position the position of the road
* @return the owner of the road at the given position
*/
Optional<String> getRoadOwner(RoadPosition position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ public void setRobberPosition(final TilePosition coordinates) {
public Optional<String> getPropertyOwner(PropertyPosition position) {
return this.propertyManager.getPropertyOwner(position).map(Player::getName);
}

@Override
public Optional<String> getRoadOwner(RoadPosition position) {
return this.roadManager.getRoadOwner(position).map(Player::getName);
}
}
6 changes: 6 additions & 0 deletions src/main/java/it/unibo/model/road/RoadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ public interface RoadManager {
*/
Optional<Player> getLongestRoadOwner();

/**
* @param position the position of the road
* @return the owner of the road at the given position
*/
Optional<Player> getRoadOwner(RoadPosition position);

}
5 changes: 5 additions & 0 deletions src/main/java/it/unibo/model/road/RoadManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ && getLongestRoadLength(player) > getLongestRoadLength(longestRoadOwner.get())))
}
}

@Override
public Optional<Player> getRoadOwner(RoadPosition position) {
return roads.stream().filter(r -> r.getPosition().equals(position)).findFirst().map(r -> r.getOwner());
}

}

0 comments on commit cc7552d

Please sign in to comment.