diff options
author | Pacien TRAN-GIRARD | 2016-04-10 23:08:47 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-04-10 23:08:47 +0200 |
commit | b0f608bb50b9a58a3ea4ebc7eb7be95e771aa360 (patch) | |
tree | 4dfc5538ee9660ef231f92fcb92999f7c3ee46f8 /src | |
parent | 08f96ef00c34340fe298757f7123445b4a36a038 (diff) | |
download | xblast-b0f608bb50b9a58a3ea4ebc7eb7be95e771aa360.tar.gz |
Handle stop speed change events
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 364a564..65309d5 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java | |||
@@ -179,11 +179,10 @@ public final class GameState { | |||
179 | Map<PlayerID, Optional<Direction>> speedChangeEvents) { | 179 | Map<PlayerID, Optional<Direction>> speedChangeEvents) { |
180 | 180 | ||
181 | return players0.stream() | 181 | return players0.stream() |
182 | .map(p -> { | 182 | .map(p -> GameState.nextPlayer( |
183 | Optional<Direction> speedChangeEvent = speedChangeEvents.get(p.id()); | 183 | p, playerBonuses.get(p.id()), |
184 | Direction requestedDirection = speedChangeEvent != null ? speedChangeEvent.orElse(null) : null; | 184 | bombedCells1, board1, blastedCells1, |
185 | return GameState.nextPlayer(p, playerBonuses.get(p.id()), bombedCells1, board1, blastedCells1, requestedDirection); | 185 | speedChangeEvents.get(p.id()))) |
186 | }) | ||
187 | .collect(Collectors.toList()); | 186 | .collect(Collectors.toList()); |
188 | } | 187 | } |
189 | 188 | ||
@@ -200,7 +199,7 @@ public final class GameState { | |||
200 | */ | 199 | */ |
201 | private static Player nextPlayer(Player player0, Bonus playerBonus, | 200 | private static Player nextPlayer(Player player0, Bonus playerBonus, |
202 | Set<Cell> bombedCells1, Board board1, Set<Cell> blastedCells1, | 201 | Set<Cell> bombedCells1, Board board1, Set<Cell> blastedCells1, |
203 | Direction requestedDirection) { | 202 | Optional<Direction> requestedDirection) { |
204 | 203 | ||
205 | // 1. Compute the new path to follow | 204 | // 1. Compute the new path to follow |
206 | Sq<Player.DirectedPosition> updatedPath = GameState.nextPath(player0.directedPositions(), requestedDirection); | 205 | Sq<Player.DirectedPosition> updatedPath = GameState.nextPath(player0.directedPositions(), requestedDirection); |
@@ -228,14 +227,17 @@ public final class GameState { | |||
228 | * @param newDir the new requested Direction | 227 | * @param newDir the new requested Direction |
229 | * @return the new path | 228 | * @return the new path |
230 | */ | 229 | */ |
231 | private static Sq<Player.DirectedPosition> nextPath(Sq<Player.DirectedPosition> p0, Direction newDir) { | 230 | private static Sq<Player.DirectedPosition> nextPath(Sq<Player.DirectedPosition> p0, Optional<Direction> newDir) { |
232 | if (Objects.isNull(newDir)) | 231 | if (Objects.isNull(newDir)) |
233 | return p0; | 232 | return p0; |
234 | 233 | ||
235 | if (p0.head().direction().isPerpendicularTo(newDir)) | 234 | if (!newDir.isPresent()) |
236 | return GameState.pivotPath(Player.DirectedPosition.moving(p0.head()), newDir); | 235 | return Player.DirectedPosition.stopped(p0.head()); |
237 | 236 | ||
238 | return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir)); | 237 | if (p0.head().direction().isPerpendicularTo(newDir.get())) |
238 | return GameState.pivotPath(Player.DirectedPosition.moving(p0.head()), newDir.get()); | ||
239 | |||
240 | return Player.DirectedPosition.moving(new Player.DirectedPosition(p0.head().position(), newDir.get())); | ||
239 | } | 241 | } |
240 | 242 | ||
241 | /** | 243 | /** |
@@ -304,7 +306,7 @@ public final class GameState { | |||
304 | */ | 306 | */ |
305 | private static boolean isColliding(Sq<Player.DirectedPosition> path, Board board1, Set<Cell> bombedCells1) { | 307 | private static boolean isColliding(Sq<Player.DirectedPosition> path, Board board1, Set<Cell> bombedCells1) { |
306 | SubCell nextPos = path.tail().head().position(); | 308 | SubCell nextPos = path.tail().head().position(); |
307 | SubCell nextCentralPos = GameState.nextCentralPosition(path.tail()); | 309 | SubCell nextCentralPos = GameState.nextCentralPosition(Player.DirectedPosition.moving(path.tail().head())); |
308 | 310 | ||
309 | if (!board1.blockAt(nextCentralPos.containingCell()).canHostPlayer()) | 311 | if (!board1.blockAt(nextCentralPos.containingCell()).canHostPlayer()) |
310 | return true; | 312 | return true; |