From 936267c0e4cd775c13cb72cc3df5c0e8f6765284 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Fri, 8 Apr 2016 13:15:25 +0200 Subject: Fix nextBlast & crumbling walls --- src/ch/epfl/xblast/server/GameState.java | 46 +++++++++++++++++++------------- src/ch/epfl/xblast/server/Ticks.java | 1 - 2 files changed, 28 insertions(+), 19 deletions(-) (limited to 'src') 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 { * @return the position of the explosion's particles for the next state. */ private static List> nextBlasts(List> blasts0, Board board0, List>> explosions0) { - return Stream.concat( - blasts0.stream() - .filter(blastSeq -> !blastSeq.tail().isEmpty()) - .map(Sq::tail), - explosions0.stream() - .map(Sq::head) - ) - .filter(blastSeq -> board0.blockAt(blastSeq.head()).isFree()) - .collect(Collectors.toList()); + List> nextBlasts = new ArrayList<>(); + for(Sq blast : blasts0){ + Sq t = blast.tail(); + if(!t.isEmpty() && board0.blockAt(blast.head()).isFree()) + nextBlasts.add(t); + } + for(Sq> explosion : explosions0){ + if(explosion.isEmpty()) + continue; + Sq b = explosion.head(); + if(!b.isEmpty()) + nextBlasts.add(b); + } + return nextBlasts; } /** @@ -185,9 +190,9 @@ public final class GameState { } // Generate the new Sequence of Directed Positions (kinda ugly right now) - if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't movex + if (!player0.lifeState().canMove() && requestedDirection != null) { // if the player can't move directedPositions1 = Player.DirectedPosition.stopped(player0.directedPositions().head()); - } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel directionx + } else if (player0.direction().isParallelTo(requestedDirection)) { // if the player want to go to a parallel direction Player.DirectedPosition requestedDirectedPosition = new Player.DirectedPosition(player0.position(), requestedDirection); directedPositions1 = Player.DirectedPosition.moving(requestedDirectedPosition); } else if (player0.direction().isPerpendicularTo(requestedDirection)) { // if the player want to go to a perpendicular direction @@ -201,18 +206,23 @@ public final class GameState { directedPositions1 = directedPositions1.tail(); // Check possible collisions and update the Sequence if necessary (kinda ugly right now) - Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); - if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free - Sq actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); - directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick - } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { - Sq actualDirectedPosition = Sq.repeat(1 , player0.directedPositions().head()); + if (player0.lifeState().canMove()) { + Cell possiblyBlockingCell = directedPositions1.tail().findFirst(dp -> dp.position().isCentral()).position().containingCell(); + if (!board1.blockAt(possiblyBlockingCell).canHostPlayer()) { // if block non-free + Sq actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); + directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick + } else if (bombedCells1.contains(possiblyBlockingCell) && possiblyBlockingCell.equals(player0.position().containingCell()) && player0.position().distanceToCentral() == Board.BOMB_BLOCKING_DISTANCE) { + Sq actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); + directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick + } + } else { + Sq actualDirectedPosition = Sq.repeat(1, player0.directedPositions().head()); directedPositions1 = actualDirectedPosition.concat(directedPositions1); // won't move for a tick } // Apply damages and generate a new LifeState Sequence Sq lifeStates1; - if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position())) { + if (player0.lifeState().state() == Player.LifeState.State.VULNERABLE && blastedCells1.contains(directedPositions1.head().position().containingCell())) { lifeStates1 = player0.statesForNextLife(); } else { 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 { * Duration of crumbling of a wall (in ticks). */ int WALL_CRUMBLING_TICKS = EXPLOSION_TICKS; - /** * Duration of the presence of a bonus (in ticks). */ -- cgit v1.2.3