diff options
author | Timothée Floure | 2016-04-08 13:15:25 +0200 |
---|---|---|
committer | Timothée Floure | 2016-04-08 13:15:25 +0200 |
commit | 936267c0e4cd775c13cb72cc3df5c0e8f6765284 (patch) | |
tree | acdecb2d4410ad2503a6e120f4069551fe35568d /src/ch/epfl | |
parent | 22b615543b70fd011f8e5e7ed9d8ae82654e5b0c (diff) | |
download | xblast-936267c0e4cd775c13cb72cc3df5c0e8f6765284.tar.gz |
Fix nextBlast & crumbling walls
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 46 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Ticks.java | 1 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 3df5ebd..a313eab 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java | |||
@@ -101,15 +101,20 @@ public final class GameState { | |||
101 | * @return the position of the explosion's particles for the next state. | 101 | * @return the position of the explosion's particles for the next state. |
102 | */ | 102 | */ |
103 | private static List<Sq<Cell>> nextBlasts(List<Sq<Cell>> blasts0, Board board0, List<Sq<Sq<Cell>>> explosions0) { | 103 | private static List<Sq<Cell>> nextBlasts(List<Sq<Cell>> blasts0, Board board0, List<Sq<Sq<Cell>>> explosions0) { |
104 | return Stream.concat( | 104 | List<Sq<Cell>> nextBlasts = new ArrayList<>(); |
105 | blasts0.stream() | 105 | for(Sq<Cell> blast : blasts0){ |
106 | .filter(blastSeq -> !blastSeq.tail().isEmpty()) | 106 | Sq<Cell> t = blast.tail(); |
107 | .map(Sq::tail), | 107 | if(!t.isEmpty() && board0.blockAt(blast.head()).isFree()) |
108 | explosions0.stream() | 108 | nextBlasts.add(t); |
109 | .map(Sq::head) | 109 | } |
110 | ) | 110 | for(Sq<Sq<Cell>> explosion : explosions0){ |
111 | .filter(blastSeq -> board0.blockAt(blastSeq.head()).isFree()) | 111 | if(explosion.isEmpty()) |
112 | .collect(Collectors.toList()); | 112 | continue; |
113 | Sq<Cell> b = explosion.head(); | ||
114 | if(!b.isEmpty()) | ||
115 | nextBlasts.add(b); | ||
116 | } | ||
117 | return nextBlasts; | ||
113 | } | 118 | } |
114 | 119 | ||
115 | /** | 120 | /** |
@@ -185,9 +190,9 @@ public final class GameState { | |||
185 | } | 190 | } |
186 | 191 | ||
187 | // Generate the new Sequence of Directed Positions (kinda ugly right now) | 192 | // Generate the new Sequence of Directed Positions (kinda ugly right now) |
188 | if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't movex | 193 | if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't move |
189 | directedPositions1 = Player.DirectedPosition.stopped(player0.directedPositions().head()); | 194 | directedPositions1 = Player.DirectedPosition.stopped(player0.directedPositions().head()); |
190 | } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel directionx | 195 | } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel direction |
191 | Player.DirectedPosition requestedDirectedPosition = new Player.DirectedPosition(player0.position(), requestedDirection); | 196 | Player.DirectedPosition requestedDirectedPosition = new Player.DirectedPosition(player0.position(), requestedDirection); |
192 | directedPositions1 = Player.DirectedPosition.moving(requestedDirectedPosition); | 197 | directedPositions1 = Player.DirectedPosition.moving(requestedDirectedPosition); |
193 | } else if (player0.direction().isPerpendicularTo(requestedDirection)) { // if the player want to go to a perpendicular direction | 198 | } else if (player0.direction().isPerpendicularTo(requestedDirection)) { // if the player want to go to a perpendicular direction |
@@ -201,18 +206,23 @@ public final class GameState { | |||
201 | directedPositions1 = directedPositions1.tail(); | 206 | directedPositions1 = directedPositions1.tail(); |
202 | 207 | ||
203 | // Check possible collisions and update the Sequence if necessary (kinda ugly right now) | 208 | // Check possible collisions and update the Sequence if necessary (kinda ugly right now) |
204 | Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); | 209 | if (player0.lifeState().canMove()) { |
205 | if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free | 210 | Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); |
206 | Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); | 211 | if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free |
207 | directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick | 212 | Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); |
208 | } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { | 213 | directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick |
209 | Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); | 214 | } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { |
215 | Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); | ||
216 | directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick | ||
217 | } | ||
218 | } else { | ||
219 | Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); | ||
210 | directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick | 220 | directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick |
211 | } | 221 | } |
212 | 222 | ||
213 | // Apply damages and generate a new LifeState Sequence | 223 | // Apply damages and generate a new LifeState Sequence |
214 | Sq<Player.LifeState> lifeStates1; | 224 | Sq<Player.LifeState> lifeStates1; |
215 | if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position())) { | 225 | if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position().containingCell())) { |
216 | lifeStates1 = player0.statesForNextLife(); | 226 | lifeStates1 = player0.statesForNextLife(); |
217 | } else { | 227 | } else { |
218 | lifeStates1 = player0.lifeStates().tail(); | 228 | lifeStates1 = player0.lifeStates().tail(); |
diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index b880dd7..a4c3e74 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java | |||
@@ -34,7 +34,6 @@ public interface Ticks { | |||
34 | * Duration of crumbling of a wall (in ticks). | 34 | * Duration of crumbling of a wall (in ticks). |
35 | */ | 35 | */ |
36 | int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; | 36 | int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; |
37 | |||
38 | /** | 37 | /** |
39 | * Duration of the presence of a bonus (in ticks). | 38 | * Duration of the presence of a bonus (in ticks). |
40 | */ | 39 | */ |