aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index a313eab..e75da1d 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -101,20 +101,16 @@ 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 List<Sq<Cell>> nextBlasts = new ArrayList<>(); 104 return Stream.concat(
105 for(Sq<Cell> blast : blasts0){ 105 blasts0.stream()
106 Sq<Cell> t = blast.tail(); 106 .filter(b -> !b.tail().isEmpty())
107 if(!t.isEmpty() && board0.blockAt(blast.head()).isFree()) 107 .filter(b -> board0.blockAt(b.head()).isFree())
108 nextBlasts.add(t); 108 .map(Sq::tail),
109 } 109 explosions0.stream()
110 for(Sq<Sq<Cell>> explosion : explosions0){ 110 .filter(e -> !e.isEmpty())
111 if(explosion.isEmpty()) 111 .map(Sq::head)
112 continue; 112 .filter(b -> !b.isEmpty()))
113 Sq<Cell> b = explosion.head(); 113 .collect(Collectors.toList());
114 if(!b.isEmpty())
115 nextBlasts.add(b);
116 }
117 return nextBlasts;
118 } 114 }
119 115
120 /** 116 /**
@@ -190,9 +186,9 @@ public final class GameState {
190 } 186 }
191 187
192 // Generate the new Sequence of Directed Positions (kinda ugly right now) 188 // Generate the new Sequence of Directed Positions (kinda ugly right now)
193 if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't move 189 if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't movex
194 directedPositions1 = Player.DirectedPosition.stopped(player0.directedPositions().head()); 190 directedPositions1 = Player.DirectedPosition.stopped(player0.directedPositions().head());
195 } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel direction 191 } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel directionx
196 Player.DirectedPosition requestedDirectedPosition = new Player.DirectedPosition(player0.position(), requestedDirection); 192 Player.DirectedPosition requestedDirectedPosition = new Player.DirectedPosition(player0.position(), requestedDirection);
197 directedPositions1 = Player.DirectedPosition.moving(requestedDirectedPosition); 193 directedPositions1 = Player.DirectedPosition.moving(requestedDirectedPosition);
198 } else if (player0.direction().isPerpendicularTo(requestedDirection)) { // if the player want to go to a perpendicular direction 194 } else if (player0.direction().isPerpendicularTo(requestedDirection)) { // if the player want to go to a perpendicular direction
@@ -206,23 +202,18 @@ public final class GameState {
206 directedPositions1 = directedPositions1.tail(); 202 directedPositions1 = directedPositions1.tail();
207 203
208 // Check possible collisions and update the Sequence if necessary (kinda ugly right now) 204 // Check possible collisions and update the Sequence if necessary (kinda ugly right now)
209 if (player0.lifeState().canMove()) { 205 Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell();
210 Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); 206 if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free
211 if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free 207 Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head());
212 Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); 208 directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick
213 directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick 209 } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) {
214 } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { 210 Sq<Player.DirectedPosition> actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head());
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());
220 directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick 211 directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick
221 } 212 }
222 213
223 // Apply damages and generate a new LifeState Sequence 214 // Apply damages and generate a new LifeState Sequence
224 Sq<Player.LifeState> lifeStates1; 215 Sq<Player.LifeState> lifeStates1;
225 if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position().containingCell())) { 216 if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position())) {
226 lifeStates1 = player0.statesForNextLife(); 217 lifeStates1 = player0.statesForNextLife();
227 } else { 218 } else {
228 lifeStates1 = player0.lifeStates().tail(); 219 lifeStates1 = player0.lifeStates().tail();