aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java')
-rw-r--r--src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java b/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java
deleted file mode 100644
index 9d5aa9f..0000000
--- a/src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java
+++ /dev/null
@@ -1,69 +0,0 @@
1package fr.umlv.java.wallj.viewer;
2
3import fr.umlv.java.wallj.board.TileVec2;
4import fr.umlv.java.wallj.event.*;
5import fr.umlv.zen5.ApplicationContext;
6import fr.umlv.zen5.Event;
7import fr.umlv.zen5.KeyboardKey;
8import org.jbox2d.common.Vec2;
9
10import java.awt.geom.Point2D;
11import java.util.LinkedList;
12import java.util.List;
13import java.util.Objects;
14
15
16/**
17 * Treats the inputs from the keyboard and mouse provided by Zen 5 and creates Events meaningful for the game.
18 *
19 * @author Adam NAILI
20 */
21public final class InputHandler {
22 private final ApplicationContext applicationContext;
23
24 /**
25 * @param applicationContext the Zen5 application context
26 */
27 public InputHandler(ApplicationContext applicationContext) {
28 this.applicationContext = Objects.requireNonNull(applicationContext);
29 }
30
31 /**
32 * @return the list of events converted from Zen 5 events to game events
33 */
34 public List<fr.umlv.java.wallj.event.Event> getEvents() {
35 LinkedList<fr.umlv.java.wallj.event.Event> events = new LinkedList<>();
36 fr.umlv.zen5.Event event = applicationContext.pollEvent();
37 if (event != null) {
38 Event.Action action = event.getAction();
39 Point2D.Float location = event.getLocation();
40 if (location != null) { //Mouse Handling
41 if (action == Event.Action.POINTER_DOWN) {
42 Vec2 mouseLocation = new Vec2(location.x, location.y);
43 TileVec2 mouseTileLocation = TileVec2.of(mouseLocation);
44 events.add(new MoveRobotOrder(mouseTileLocation));
45 }
46 }
47 KeyboardKey keyboardKey = event.getKey();
48 if (keyboardKey != null) { //Keyboard Handling
49 if (action == Event.Action.KEY_PRESSED) {
50 switch (keyboardKey) {
51 case SPACE:
52 events.add(new BombSetupOrder());
53 break;
54 case R:
55 events.add(new ConfirmOrder());
56 break;
57 case Q:
58 events.add(new QuitGameOrder());
59 break;
60 case S:
61 events.add(new SimulationStartOrder());
62 break;
63 }
64 }
65 }
66 }
67 return events;
68 }
69}