Skip to content

Commit

Permalink
PlacedTile coding style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mw3y committed Apr 8, 2024
1 parent c9e3094 commit 552d715
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/ch/epfl/chacun/PlacedTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents a tile that has been placed on the board.
Expand Down Expand Up @@ -89,8 +88,8 @@ public TileSide side(Direction direction) {
* @throws IllegalArgumentException if the tile has no area with this id
*/
public Zone zoneWithId(int id) {
return tile.zones().stream().filter(z -> z.id() == id).findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unknown zone id: " + id));
return tile.zones().stream().filter(z -> z.id() == id)
.findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown zone id: " + id));
}

/**
Expand All @@ -99,7 +98,8 @@ public Zone zoneWithId(int id) {
* @return the special power zone of the placed tile or null if there is none
*/
public Zone specialPowerZone() {
return tile.zones().stream().filter(z -> z.specialPower() != null).findFirst().orElse(null);
return tile.zones().stream().filter(z -> z.specialPower() != null)
.findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -156,13 +156,11 @@ public Set<Occupant> potentialOccupants() {
if (placer != null) {
for (Zone zone : tile.zones()) {
// A pawn can only be placed on a meadow, a forest or a river
if (!(zone instanceof Zone.Lake)) {
if (!(zone instanceof Zone.Lake))
potentialOccupants.add(new Occupant(Occupant.Kind.PAWN, zone.id()));
}
// A hut can only be placed on a lake or on a river if there's no lake
if (zone instanceof Zone.Lake || (zone instanceof Zone.River river && !river.hasLake())) {
if (zone instanceof Zone.Lake || (zone instanceof Zone.River river && !river.hasLake()))
potentialOccupants.add(new Occupant(Occupant.Kind.HUT, zone.id()));
}
}
}
return potentialOccupants;
Expand Down Expand Up @@ -197,9 +195,8 @@ public PlacedTile withNoOccupant() {
* @return the id of the zone occupied by the given kind of occupant, or -1 if there is none
*/
public int idOfZoneOccupiedBy(Occupant.Kind occupantKind) {
if (occupant != null && occupant.kind() == occupantKind) {
if (occupant != null && occupant.kind() == occupantKind)
return occupant.zoneId();
}
return -1;
}

Expand Down

0 comments on commit 552d715

Please sign in to comment.