Skip to content

Package: IC4Field

IC4Field

Coverage

1: package de.fhdw.gaming.ipspiel23.c4.domain;
2:
3: import java.util.Optional;
4:
5: import de.fhdw.gaming.core.domain.Stateful;
6:
7: /**
8: * A field of the connect four game.
9: */
10: public interface IC4Field extends Stateful {
11:
12: /**
13: * The board that contains this field.
14: */
15: IC4Board getBoard();
16:
17: /**
18: * The position of this field on the board.
19: */
20: IC4Position getBoardPosition();
21:
22: /**
23: * The player that occupies this field, if any.
24: */
25: Optional<IC4Player> getOccupyingPlayer();
26:
27: /**
28: * Tries to set the occupying player of this field.
29: * @param player The player to set.
30: * @param allowOverride Whether to allow overriding an existing occupying player.
31: * @return {@code true} if the occupying player was successfully set, {@code false} if the field was
32: * already occupied and {@code allowOverride} was {@code false} or if setting the occupying player
33: * would violate the rules of the game.
34: */
35: boolean trySetOccupyingPlayer(IC4Player player, boolean allowOverride);
36:
37: /**
38: * Whether this field has a neighbor in the given direction (i.e., whether the field is not at the
39: * edge of the board).
40: *
41: * @param direction The direction to check.
42: * @return {@code true} if this field has a neighbor in the given direction, {@code false} otherwise.
43: */
44: boolean hasNeighbor(C4Direction direction);
45:
46: /**
47: * Gets the neighbor of this field in the given direction.
48: *
49: * @param direction The direction to get the neighbor for.
50: * @return The neighbor of this field in the given direction.
51: * @throws IllegalArgumentException If this field has no neighbor in the given direction (i.e., if
52: * the neighbor would be outside the board).
53: */
54: IC4Field getNeighbor(C4Direction direction);
55:
56: /**
57: * Tries to get the neighbor of this field in the given direction.
58: *
59: * @param direction The direction to get the neighbor for.
60: * @return The neighbor of this field in the given direction, if any.
61: */
62: Optional<IC4Field> tryGetNeighbor(C4Direction direction);
63:
64: @Override
65: IC4Field deepCopy();
66: }