diff options
Diffstat (limited to 'src/ch/epfl/xblast/server/GameState.java')
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 16cb01b..a5e1378 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java | |||
@@ -207,6 +207,24 @@ public final class GameState { | |||
207 | return new GameState(this.ticks + 1, board1, players1, bombs1, explosions1, blasts1); | 207 | return new GameState(this.ticks + 1, board1, players1, bombs1, explosions1, blasts1); |
208 | } | 208 | } |
209 | 209 | ||
210 | /** | ||
211 | * Computes and returns the game state for the next tick, given the current state and the given events. | ||
212 | * | ||
213 | * @param playerActions the player actions map | ||
214 | * @return the next game state | ||
215 | */ | ||
216 | public GameState next(Map<PlayerID, PlayerAction> playerActions) { | ||
217 | Map<PlayerID, Optional<Direction>> speedChangeEvents = playerActions.entrySet().stream() | ||
218 | .filter(e -> Objects.nonNull(e.getValue().associatedSpeedChangeEvent())) | ||
219 | .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().associatedSpeedChangeEvent())); | ||
220 | |||
221 | Set<PlayerID> bombDropEvents = playerActions.entrySet().stream() | ||
222 | .filter(e -> e.getValue() == PlayerAction.DROP_BOMB) | ||
223 | .map(Map.Entry::getKey) | ||
224 | .collect(Collectors.toSet()); | ||
225 | |||
226 | return this.next(speedChangeEvents, bombDropEvents); | ||
227 | } | ||
210 | 228 | ||
211 | /** | 229 | /** |
212 | * Returns a mapping of players from their location. | 230 | * Returns a mapping of players from their location. |