diff options
author | Adam NAILI | 2018-02-04 22:35:17 +0100 |
---|---|---|
committer | Adam NAILI | 2018-02-04 22:35:17 +0100 |
commit | ffcfda13284855a3055c153d5bc6a804d998c62d (patch) | |
tree | 39cf004396874a5857cc003156600c3805661be5 | |
parent | 7036d33e4d708c2282c7a145bc952faf5dd15adf (diff) | |
parent | 276753488bf2e6670bdd77d59042ed168e807a40 (diff) | |
download | wallj-ffcfda13284855a3055c153d5bc6a804d998c62d.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
-rw-r--r-- | src/docs/class.puml | 14 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/InputHandler.java | 69 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/Main.java | 3 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/ScreenManager.java | 40 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/Viewer.java | 104 |
5 files changed, 77 insertions, 153 deletions
diff --git a/src/docs/class.puml b/src/docs/class.puml index 7bfccca..5c00dcf 100644 --- a/src/docs/class.puml +++ b/src/docs/class.puml | |||
@@ -11,20 +11,6 @@ package viewer { | |||
11 | void eventLoop(ApplicationContext) | 11 | void eventLoop(ApplicationContext) |
12 | } | 12 | } |
13 | 13 | ||
14 | class InputHandler { | ||
15 | ApplicationContext | ||
16 | |||
17 | InputHandler(ApplicationContext) | ||
18 | List<Event> getEvents() | ||
19 | } | ||
20 | |||
21 | class ScreenManager { | ||
22 | ApplicationContext, Graphics2D | ||
23 | |||
24 | ScreenManager(ApplicationContext,Graphics2D) | ||
25 | GraphicsContext clearScreen() | ||
26 | } | ||
27 | |||
28 | class Main { | 14 | class Main { |
29 | static void main(String[]) | 15 | static void main(String[]) |
30 | } | 16 | } |
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 @@ | |||
1 | package fr.umlv.java.wallj.viewer; | ||
2 | |||
3 | import fr.umlv.java.wallj.board.TileVec2; | ||
4 | import fr.umlv.java.wallj.event.*; | ||
5 | import fr.umlv.zen5.ApplicationContext; | ||
6 | import fr.umlv.zen5.Event; | ||
7 | import fr.umlv.zen5.KeyboardKey; | ||
8 | import org.jbox2d.common.Vec2; | ||
9 | |||
10 | import java.awt.geom.Point2D; | ||
11 | import java.util.LinkedList; | ||
12 | import java.util.List; | ||
13 | import 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 | */ | ||
21 | public 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 | } | ||
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Main.java b/src/main/java/fr/umlv/java/wallj/viewer/Main.java index 4483069..064eed3 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Main.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Main.java | |||
@@ -83,8 +83,7 @@ public final class Main { | |||
83 | .map(Main::validateBoard) | 83 | .map(Main::validateBoard) |
84 | .collect(Collectors.toList()); | 84 | .collect(Collectors.toList()); |
85 | 85 | ||
86 | Viewer viewer = new Viewer(levels); | 86 | Application.run(Viewer.BACKGROUND_COLOR, appContext -> (new Viewer(appContext, levels)).run()); |
87 | Application.run(Viewer.BACKGROUND_COLOR, viewer::eventLoop); | ||
88 | } | 87 | } |
89 | 88 | ||
90 | private Main() { | 89 | private Main() { |
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/ScreenManager.java b/src/main/java/fr/umlv/java/wallj/viewer/ScreenManager.java deleted file mode 100644 index be16067..0000000 --- a/src/main/java/fr/umlv/java/wallj/viewer/ScreenManager.java +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | package fr.umlv.java.wallj.viewer; | ||
2 | |||
3 | import fr.umlv.java.wallj.context.GraphicsContext; | ||
4 | import fr.umlv.zen5.ApplicationContext; | ||
5 | import fr.umlv.zen5.ScreenInfo; | ||
6 | import org.jbox2d.common.Vec2; | ||
7 | |||
8 | import java.awt.Graphics2D; | ||
9 | import java.util.Objects; | ||
10 | |||
11 | /** | ||
12 | * Generates a clean GraphicsContext | ||
13 | * | ||
14 | * @author Adam NAILI | ||
15 | */ | ||
16 | public final class ScreenManager { | ||
17 | private final ApplicationContext applicationContext; | ||
18 | private final Graphics2D graphics2D; | ||
19 | |||
20 | /** | ||
21 | * | ||
22 | * @param applicationContext the current application context | ||
23 | * @param graphics2D the current graphics2D | ||
24 | */ | ||
25 | public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) { | ||
26 | this.applicationContext = Objects.requireNonNull(applicationContext); | ||
27 | this.graphics2D = Objects.requireNonNull(graphics2D); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * | ||
32 | * @return a graphic context | ||
33 | */ | ||
34 | public GraphicsContext clearScreen() { | ||
35 | ScreenInfo screenInfo = applicationContext.getScreenInfo(); | ||
36 | GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo); | ||
37 | graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight()); | ||
38 | return graphicsContext; | ||
39 | } | ||
40 | } | ||
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java index b9686b0..ea6f3d0 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java | |||
@@ -1,63 +1,111 @@ | |||
1 | package fr.umlv.java.wallj.viewer; | 1 | package fr.umlv.java.wallj.viewer; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | 3 | import fr.umlv.java.wallj.board.Board; |
4 | import fr.umlv.java.wallj.board.TileVec2; | ||
4 | import fr.umlv.java.wallj.context.Context; | 5 | import fr.umlv.java.wallj.context.Context; |
5 | import fr.umlv.java.wallj.context.Game; | 6 | import fr.umlv.java.wallj.context.Game; |
7 | import fr.umlv.java.wallj.context.GraphicsContext; | ||
8 | import fr.umlv.java.wallj.event.*; | ||
6 | import fr.umlv.java.wallj.event.Event; | 9 | import fr.umlv.java.wallj.event.Event; |
7 | import fr.umlv.zen5.ApplicationContext; | 10 | import fr.umlv.zen5.ApplicationContext; |
11 | import fr.umlv.zen5.ScreenInfo; | ||
12 | import org.jbox2d.common.Vec2; | ||
8 | 13 | ||
9 | import java.awt.*; | 14 | import java.awt.*; |
15 | import java.awt.geom.Point2D; | ||
10 | import java.time.Duration; | 16 | import java.time.Duration; |
11 | import java.util.LinkedList; | 17 | import java.util.LinkedList; |
12 | import java.util.List; | 18 | import java.util.List; |
13 | import java.util.Objects; | 19 | import java.util.Objects; |
14 | import java.util.stream.Collectors; | 20 | import java.util.stream.Collectors; |
21 | import java.util.stream.Stream; | ||
15 | 22 | ||
16 | /** | 23 | /** |
17 | * Link between application and Zen 5 | 24 | * Link between application and Zen 5 |
18 | * | 25 | * |
19 | * @author Adam NAILI | 26 | * @author Adam NAILI |
27 | * @author Pacien TRAN-GIRARD | ||
20 | */ | 28 | */ |
21 | public final class Viewer { | 29 | public final class Viewer { |
22 | public static final Color BACKGROUND_COLOR = Color.WHITE; | 30 | public static final Color BACKGROUND_COLOR = Color.WHITE; |
31 | |||
23 | private static final Duration FRAME_DURATION = Duration.ofMillis(1000 / 60); | 32 | private static final Duration FRAME_DURATION = Duration.ofMillis(1000 / 60); |
33 | private static int EXIT_OK = 0; | ||
24 | 34 | ||
25 | private final Game currentGame; | 35 | private final ApplicationContext appContext; |
36 | private final Game game; | ||
26 | 37 | ||
27 | /** | 38 | /** |
28 | * @param boards the valid list of boards charged in the application | 39 | * @param boards the valid list of boards charged in the application |
29 | */ | 40 | */ |
30 | public Viewer(List<Board> boards) { | 41 | public Viewer(ApplicationContext appContext, List<Board> boards) { |
31 | this.currentGame = new Game(Objects.requireNonNull(boards)); | 42 | this.appContext = Objects.requireNonNull(appContext); |
43 | this.game = new Game(boards); | ||
32 | } | 44 | } |
33 | 45 | ||
34 | /** |