aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/server/GameState.java
diff options
context:
space:
mode:
authorTimothée Floure2016-05-27 13:47:51 +0200
committerTimothée Floure2016-05-27 13:47:51 +0200
commite7382c3c2a28109b18492e9a62265c51b1be94dd (patch)
tree68b75b4968f74ddde01d012cccc5cf596a823ec0 /src/ch/epfl/xblast/server/GameState.java
parent7d9c28e25d5b0965171f4b347852a11fdf01482e (diff)
parenta82a8ba2611378ff6fb1cd226fb3d579d43d6e89 (diff)
downloadxblast-master.tar.gz
Merge branch '11_network' into 'master' HEADmaster
11 network See merge request !11
Diffstat (limited to 'src/ch/epfl/xblast/server/GameState.java')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java18
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.