diff options
author | pacien | 2018-02-01 20:29:40 +0100 |
---|---|---|
committer | pacien | 2018-02-01 20:29:40 +0100 |
commit | 735be27e8802740cf0986bb6d14e720234889aae (patch) | |
tree | d3f479d4cf7b3f7082477ce18031b0c4b1f95c52 /src | |
parent | 1a1d90fc6edc85fc3d6440db3a5d582a69a5441d (diff) | |
download | wallj-735be27e8802740cf0986bb6d14e720234889aae.tar.gz |
Rename events/orders ; Partial impl. of robot event handling
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src')
13 files changed, 106 insertions, 73 deletions
diff --git a/src/docs/class.puml b/src/docs/class.puml index cfc78b1..151e334 100644 --- a/src/docs/class.puml +++ b/src/docs/class.puml | |||
@@ -87,26 +87,24 @@ package context { | |||
87 | 87 | ||
88 | package event { | 88 | package event { |
89 | interface Event | 89 | interface Event |
90 | |||
91 | interface InputEvent implements Event | ||
92 | interface GameEvent implements Event | 90 | interface GameEvent implements Event |
91 | interface InputEvent implements Event | ||
93 | 92 | ||
94 | class DropBombEvent implements InputEvent | 93 | class ConfirmOrder implements InputEvent |
94 | class BombSetupOrder implements InputEvent | ||
95 | 95 | ||
96 | class AddBombEvent implements InputEvent { | 96 | class MoveRobotOrder implements InputEvent { |
97 | final TileVec2 | 97 | MoveRobotEvent(TileVec2) |
98 | AddBombEvent(TileVec2) | 98 | TileVec2 getTarget() |
99 | TileVec2 getTile() | ||
100 | } | 99 | } |
101 | 100 | ||
102 | class MoveRobotEvent implements InputEvent { | 101 | class BombSetupEvent implements GameEvent { |
103 | final TileVec2 | 102 | final TileVec2 |
104 | MoveRobotEvent(TileVec2) | 103 | AddBombEvent(TileVec2) |
105 | TileVec2 getTile() | 104 | TileVec2 getTile() |
106 | } | 105 | } |
107 | 106 | ||
108 | class ConfirmEvent implements InputEvent | 107 | class GameOverEvent implements GameEvent |
109 | class GameOverEvent implements Event | ||
110 | 108 | ||
111 | class ExplosionEvent implements GameEvent { | 109 | class ExplosionEvent implements GameEvent { |
112 | Block source | 110 | Block source |
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 45c75da..c011f27 100644 --- a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java +++ b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java | |||
@@ -1,13 +1,19 @@ | |||
1 | package fr.umlv.java.wallj.block; | 1 | package fr.umlv.java.wallj.block; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | ||
4 | import fr.umlv.java.wallj.board.PathFinder; | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | 5 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.context.Context; | 6 | import fr.umlv.java.wallj.context.Context; |
5 | import fr.umlv.java.wallj.context.GraphicsContext; | 7 | import fr.umlv.java.wallj.context.GraphicsContext; |
8 | import fr.umlv.java.wallj.event.BombSetupEvent; | ||
9 | import fr.umlv.java.wallj.event.BombSetupOrder; | ||
6 | import fr.umlv.java.wallj.event.Event; | 10 | import fr.umlv.java.wallj.event.Event; |
11 | import fr.umlv.java.wallj.event.MoveRobotOrder; | ||
7 | import org.jbox2d.common.Vec2; | 12 | import org.jbox2d.common.Vec2; |
8 | import org.jbox2d.dynamics.World; | 13 | import org.jbox2d.dynamics.World; |
9 | 14 | ||
10 | import java.awt.*; | 15 | import java.awt.*; |
16 | import java.time.Duration; | ||
11 | import java.util.Collections; | 17 | import java.util.Collections; |
12 | import java.util.List; | 18 | import java.util.List; |
13 | 19 | ||
@@ -21,6 +27,7 @@ public class RobotBlock extends Block { | |||
21 | 27 | ||
22 | private Vec2 pos; | 28 | private Vec2 pos; |
23 | private List<TileVec2> path = Collections.emptyList(); | 29 | private List<TileVec2> path = Collections.emptyList(); |
30 | private PathFinder pathFinder; | ||
24 | 31 | ||
25 | RobotBlock(Vec2 pos) { | 32 | RobotBlock(Vec2 pos) { |
26 | super(BlockType.ROBOT); | 33 | super(BlockType.ROBOT); |
@@ -39,21 +46,27 @@ public class RobotBlock extends Block { | |||
39 | 46 | ||
40 | @Override | 47 | @Override |
41 | public List<Event> update(Context context) { | 48 | public List<Event> update(Context context) { |
42 | updatePath(context.getEvents()); | 49 | Event.findFirst(context.getEvents(), MoveRobotOrder.class) |
43 | if (!path.isEmpty()) move(); | 50 | .ifPresent(event -> updatePath(context.getGame().getCurrentStage().getBoard(), event.getTarget())); |
51 | |||
52 | if (!path.isEmpty()) move(context.getTimeDelta()); | ||
44 | paint(context.getGraphicsContext()); | 53 | paint(context.getGraphicsContext()); |
45 | return setupBomb(context.getEvents()); | 54 | return setupBomb(context.getEvents()); |
46 | } | 55 | } |
47 | 56 | ||
48 | private List<Event> setupBomb(List<Event> events) { | 57 | private List<Event> setupBomb(List<Event> events) { |
49 | return Collections.emptyList(); // TODO: return a SetupBombEvent at current location if an order was received | 58 | return Event.findFirst(events, BombSetupOrder.class) |
59 | .map(event -> Collections.<Event>singletonList(new BombSetupEvent(TileVec2.of(pos)))) | ||
60 | .orElse(Collections.emptyList()); | ||
50 | } | 61 | } |
51 | 62 | ||
52 | private void updatePath(List<Event> events) { | 63 | private void updatePath(Board board, TileVec2 target) { |
53 | // TODO: update path if received a new target event (using the pathfinder) | 64 | if (!board.getBlockTypeAt(target).isTraversable()) return; |
65 | if (pathFinder == null) pathFinder = new PathFinder(board); | ||
66 | path = pathFinder.findPath(TileVec2.of(pos), target); | ||
54 | } | 67 | } |
55 | 68 | ||
56 | private void move() { | 69 | private void move(Duration timeDelta) { |
57 | // TODO: follow the current path | 70 | // TODO: follow the current path |
58 | } | 71 | } |
59 | 72 | ||
diff --git a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java index 1a64667..64591df 100644 --- a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java +++ b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java | |||
@@ -1,8 +1,8 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.event.DropBombEvent; | 4 | import fr.umlv.java.wallj.event.BombSetupOrder; |
5 | import fr.umlv.java.wallj.event.MoveRobotEvent; | 5 | import fr.umlv.java.wallj.event.MoveRobotOrder; |
6 | import fr.umlv.zen5.ApplicationContext; | 6 | import fr.umlv.zen5.ApplicationContext; |
7 | import fr.umlv.zen5.Event; | 7 | import fr.umlv.zen5.Event; |
8 | import fr.umlv.zen5.KeyboardKey; | 8 | import fr.umlv.zen5.KeyboardKey; |
@@ -43,7 +43,7 @@ public final class InputHandler { | |||
43 | if (action == Event.Action.POINTER_DOWN) { | 43 | if (action == Event.Action.POINTER_DOWN) { |
44 | Vec2 mouseLocation = new Vec2(location.x, location.y); | 44 | Vec2 mouseLocation = new Vec2(location.x, location.y); |
45 | TileVec2 mouseTileLocation = TileVec2.of(mouseLocation); | 45 | TileVec2 mouseTileLocation = TileVec2.of(mouseLocation); |
46 | events.add(new MoveRobotEvent(mouseTileLocation)); | 46 | events.add(new MoveRobotOrder(mouseTileLocation)); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | KeyboardKey keyboardKey = event.getKey(); | 49 | KeyboardKey keyboardKey = event.getKey(); |
@@ -51,7 +51,7 @@ public final class InputHandler { | |||
51 | if (action == Event.Action.KEY_PRESSED) { | 51 | if (action == Event.Action.KEY_PRESSED) { |
52 | switch (keyboardKey) { | 52 | switch (keyboardKey) { |
53 | case SPACE: | 53 | case SPACE: |
54 | events.add(new DropBombEvent()); | 54 | events.add(new BombSetupOrder()); |
55 | break; | 55 | break; |
56 | } | 56 | } |
57 | } | 57 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java index 2c548f2..c2c28a7 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GameStateController.java | |||
@@ -2,7 +2,7 @@ package fr.umlv.java.wallj.controller; | |||
2 | 2 | ||
3 | import fr.umlv.java.wallj.context.Context; | 3 | import fr.umlv.java.wallj.context.Context; |
4 | import fr.umlv.java.wallj.context.Game; | 4 | import fr.umlv.java.wallj.context.Game; |
5 | import fr.umlv.java.wallj.event.ConfirmEvent; | 5 | import fr.umlv.java.wallj.event.ConfirmOrder; |
6 | import fr.umlv.java.wallj.event.Event; | 6 | import fr.umlv.java.wallj.event.Event; |
7 | import fr.umlv.java.wallj.event.GameOverEvent; | 7 | import fr.umlv.java.wallj.event.GameOverEvent; |
8 | 8 | ||
@@ -13,7 +13,7 @@ public class GameStateController implements Controller { | |||
13 | 13 | ||
14 | @Override | 14 | @Override |
15 | public List<Event> update(Context context) { | 15 | public List<Event> update(Context context) { |
16 | boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmEvent); | 16 | boolean isConfirmEvent = context.getEvents().stream().anyMatch(event -> event instanceof ConfirmOrder); |
17 | boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof GameOverEvent); | 17 | boolean isGameOver = context.getEvents().stream().allMatch(event -> event instanceof GameOverEvent); |
18 | Game currentGame = context.getGame(); | 18 | Game currentGame = context.getGame(); |
19 | LinkedList<Event> events = new LinkedList<>(); | 19 | LinkedList<Event> events = new LinkedList<>(); |
diff --git a/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java b/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java deleted file mode 100644 index 10581ff..0000000 --- a/src/main/java/fr/umlv/java/wallj/event/AddBombEvent.java +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | package fr.umlv.java.wallj.event; | ||
2 | |||
3 | import fr.umlv.java.wallj.board.TileVec2; | ||
4 | |||
5 | import java.util.Objects; | ||
6 | |||
7 | /** | ||
8 | * Event to put a bomb on the game board | ||
9 | * | ||
10 | * @author Adam NAILI | ||
11 | */ | ||
12 | public final class AddBombEvent implements InputEvent { |