Skip to content

Package: Observer

Observer

Coverage

1: /*
2: * Copyright © 2020 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of gaming-core.
5: *
6: * Gaming-core is free software: you can redistribute it and/or modify it under
7: * the terms of the GNU General Public License as published by the Free Software
8: * Foundation, either version 3 of the License, or (at your option) any later
9: * version.
10: *
11: * Gaming-core is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14: * details.
15: *
16: * You should have received a copy of the GNU General Public License along with
17: * gaming-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.core.domain;
20:
21: import java.util.Optional;
22: import java.util.Set;
23:
24: /**
25: * Receives events about the game.
26: */
27: public interface Observer {
28:
29: /**
30: * Indicates that the game has been started.
31: *
32: * @param game The game.
33: * @param state A copy of the game state.
34: * @throws InterruptedException if the game has been interrupted while processing this event.
35: */
36: void started(Game<?, ?, ?, ?> game, State<?, ?> state) throws InterruptedException;
37:
38: /**
39: * Indicates that a new set of players being able to make a move has been computed.
40: *
41: * @param game The game.
42: * @param state A copy of the game state.
43: * @param players The set of players. May be empty if no players have been chosen.
44: * @throws InterruptedException if the game has been interrupted while processing this event.
45: */
46: void nextPlayersComputed(Game<?, ?, ?, ?> game, State<?, ?> state, Set<? extends Player<?>> players)
47: throws InterruptedException;
48:
49: /**
50: * Indicates that an illegal player has been rejected by the game.
51: *
52: * @param game The game.
53: * @param state A copy of the game state.
54: * @param player The player.
55: * @throws InterruptedException if the game has been interrupted while processing this event.
56: */
57: void illegalPlayerRejected(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> player) throws InterruptedException;
58:
59: /**
60: * Indicates that a legal move has been applied to the game state.
61: *
62: * @param game The game.
63: * @param state A copy of the game state.
64: * @param player The player.
65: * @param move The move.
66: * @throws InterruptedException if the game has been interrupted while processing this event.
67: */
68: void legalMoveApplied(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> player, Move<?, ?> move)
69: throws InterruptedException;
70:
71: /**
72: * Indicates that an illegal move has been rejected by the game.
73: *
74: * @param game The game.
75: * @param state A copy of the game state.
76: * @param player The player.
77: * @param move The move. Can be empty if no move at all has been selected by the strategy.
78: * @param reason The reason why the move is illegal.
79: * @throws InterruptedException if the game has been interrupted while processing this event.
80: */
81: void illegalMoveRejected(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> player, Optional<Move<?, ?>> move,
82: String reason) throws InterruptedException;
83:
84: /**
85: * Indicates that a move is overdue, i.e. it has exceeded its time window.
86: *
87: * @param game The game.
88: * @param state A copy of the game state.
89: * @param player The player.
90: * @param chosenMove The move that has been chosen. Can be empty if no move is available (e.g. because a player has
91: * already won the game).
92: * @throws InterruptedException if the game has been interrupted while processing this event.
93: */
94: void overdueMoveRejected(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> player,
95: Optional<Move<?, ?>> chosenMove)
96: throws InterruptedException;
97:
98: /**
99: * Indicates that a player has resigned.
100: *
101: * @param game The game.
102: * @param state A copy of the game state.
103: * @param player The player that has resigned.
104: * @throws InterruptedException if the game has been interrupted while processing this event.
105: */
106: void playerResigned(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> player) throws InterruptedException;
107:
108: /**
109: * Indicates that a player has been overtaken by some other player.
110: *
111: * @param game The game.
112: * @param state A copy of the game state.
113: * @param overtakenPlayer The overtaken player.
114: * @param overtakingPlayer The overtaking player.
115: * @throws InterruptedException if the game has been interrupted while processing this event.
116: */
117: void playerOvertaken(Game<?, ?, ?, ?> game, State<?, ?> state, Player<?> overtakenPlayer,
118: Player<?> overtakingPlayer)
119: throws InterruptedException;
120:
121: /**
122: * Indicates that the game has been finished.
123: *
124: * @param game The game.
125: * @param state A copy of the game state.
126: * @throws InterruptedException if the game has been interrupted while processing this event.
127: */
128: void finished(Game<?, ?, ?, ?> game, State<?, ?> state) throws InterruptedException;
129: }