From 30f734d6b8602410e7d57d2f9f9bd4814df9fefe Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 3 Feb 2018 22:44:09 +0100 Subject: Add simulation starting condition check Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/block/RobotBlock.java | 3 +-- src/main/java/fr/umlv/java/wallj/context/Stage.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java index e4e0aad..4d7745b 100644 --- a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java +++ b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java @@ -23,7 +23,6 @@ import java.util.List; */ public class RobotBlock extends Block { private static final float SPEED = 10f; // px/ms - private static final int MAX_BOMB_PLACEMENTS = 3; private Vec2 pos; private PathFinder pathFinder; @@ -69,7 +68,7 @@ public class RobotBlock extends Block { } private List dropBomb(BombSetupOrder order) { - if (droppedBombCount >= MAX_BOMB_PLACEMENTS) return Collections.emptyList(); + if (droppedBombCount >= Stage.BOMB_PLACEMENTS) return Collections.emptyList(); droppedBombCount++; return Collections.singletonList(new BlockCreateEvent(BlockType.BOMB, getTile())); diff --git a/src/main/java/fr/umlv/java/wallj/context/Stage.java b/src/main/java/fr/umlv/java/wallj/context/Stage.java index 49aa196..9737583 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Stage.java +++ b/src/main/java/fr/umlv/java/wallj/context/Stage.java @@ -17,6 +17,7 @@ import java.util.*; * @author Pacien TRAN-GIRARD */ public class Stage implements Updateable { + public static final int BOMB_PLACEMENTS = 3; private static final int VELOCITY_TICK_PER_MS = 6; private static final int POSITION_TICK_PER_MS = 2; @@ -60,7 +61,17 @@ public class Stage implements Updateable { * @implNote TODO: profile this and consider a garbage block counter */ public boolean isCleared() { - return blocks.stream().noneMatch(block -> block.getType() == BlockType.GARBAGE); + return blocks.stream() + .noneMatch(block -> block.getType() == BlockType.GARBAGE); + } + + /** + * @return T(the physics simulation can start, i.e. the player has placed all their bombs) + */ + public boolean isReady() { + return blocks.stream() + .filter(block -> block.getType() == BlockType.BOMB) + .count() == BOMB_PLACEMENTS; } /** -- cgit v1.2.3