diff options
Diffstat (limited to 'src/main/java/fr')
4 files changed, 194 insertions, 4 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/context/Context.java b/src/main/java/fr/umlv/java/wallj/context/Context.java index a20da6f..a924c2b 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Context.java +++ b/src/main/java/fr/umlv/java/wallj/context/Context.java | |||
@@ -1,5 +1,49 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | public class Context { | 3 | import fr.umlv.java.wallj.event.Event; |
4 | import fr.umlv.java.wallj.model.Stage; | ||
5 | |||
6 | import java.util.List; | ||
7 | import java.util.Objects; | ||
8 | |||
9 | /** | ||
10 | * A context used to store the current state of the application at one tick. | ||
11 | */ | ||
12 | public final class Context { | ||
4 | //TODO Class Context | 13 | //TODO Class Context |
14 | private final Stage stage; | ||
15 | private final List<Event> events; | ||
16 | private final GraphicsContext graphicsContext; | ||
17 | |||
18 | /** | ||
19 | * @param stage the current stage | ||
20 | * @param events the list of events of the tick | ||
21 | * @param graphicsContext the current graphics context | ||
22 | */ | ||
23 | public Context(Stage stage, List<Event> events, GraphicsContext graphicsContext) { | ||
24 | this.stage = Objects.requireNonNull(stage); | ||
25 | this.events = Objects.requireNonNull(events); | ||
26 | this.graphicsContext = Objects.requireNonNull(graphicsContext); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @return the stage | ||
31 | */ | ||
32 | public Stage getStage() { | ||
33 | return stage; | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * @return the list of events | ||
38 | */ | ||
39 | public List<Event> getEvents() { | ||
40 | return events; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * @return the graphics context | ||
45 | */ | ||
46 | public GraphicsContext getGraphicsContext() { | ||
47 | return graphicsContext; | ||
48 | } | ||
5 | } | 49 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/context/Game.java b/src/main/java/fr/umlv/java/wallj/context/Game.java index f32ed65..b3418c4 100644 --- a/src/main/java/fr/umlv/java/wallj/context/Game.java +++ b/src/main/java/fr/umlv/java/wallj/context/Game.java | |||
@@ -1,5 +1,65 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | public class Game { | 3 | import fr.umlv.java.wallj.board.Board; |
4 | import fr.umlv.java.wallj.controller.GameController; | ||
5 | |||
6 | import java.util.Collections; | ||
7 | import java.util.List; | ||
8 | import java.util.NoSuchElementException; | ||
9 | import java.util.Objects; | ||
10 | |||
11 | /** | ||
12 | * A game | ||
13 | */ | ||
14 | public final class Game { | ||
4 | //TODO | 15 | //TODO |
16 | private final GameController gameController; | ||
17 | private int indexBoard; | ||
18 | private final List<Board> boards; | ||
19 | |||
20 | /** | ||
21 | * @param gameController the controller of the game | ||
22 | * @param boards the list of boards charged for the game | ||
23 | */ | ||
24 | public Game(GameController gameController, List<Board> boards) { | ||
25 | this.gameController = Objects.requireNonNull(gameController); | ||
26 | Objects.requireNonNull(boards); | ||
27 | if (boards.isEmpty()) { | ||
28 | throw new IllegalArgumentException("The list of boards is empty, not able to create a correct game from this."); | ||
29 | } | ||
30 | this.boards = Collections.unmodifiableList(boards); | ||
31 | this.indexBoard = 0; | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @return the game controller | ||
36 | */ | ||
37 | public GameController getGameController() { | ||
38 | return gameController; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * @return the current board of the game. | ||
43 | */ | ||
44 | public Board getCurrentBoard() { | ||
45 | return boards.get(indexBoard); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @return a boolean on the condition of having a next Board in our game. | ||
50 | */ | ||
51 | public boolean hasNextBoard() { | ||
52 | return indexBoard + 1 < boards.size(); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @return the next board | ||
57 | */ | ||
58 | public Board nextBoard() { | ||
59 | if (indexBoard >= boards.size()) { | ||
60 | throw new NoSuchElementException("No more board for the game."); | ||
61 | } | ||
62 | indexBoard++; | ||
63 | return boards.get(indexBoard); | ||
64 | } | ||
5 | } | 65 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java b/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java index 57e21fe..214eeb0 100644 --- a/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java +++ b/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java | |||
@@ -1,5 +1,38 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | public class GraphicsContext { | 3 | import fr.umlv.zen5.ScreenInfo; |
4 | |||
5 | import java.awt.Graphics2D; | ||
6 | import java.util.Objects; | ||
7 | |||
8 | /** | ||
9 | * A context of the current graphic status of the application | ||
10 | */ | ||
11 | public final class GraphicsContext { | ||
4 | //TODO Class GraphicsContext | 12 | //TODO Class GraphicsContext |
13 | private final Graphics2D graphics2D; | ||
14 | private final ScreenInfo screenInfo; | ||
15 | |||
16 | /** | ||
17 | * @param graphics2D the current drawable canvas | ||
18 | * @param screenInfo the informations about the screen | ||
19 | */ | ||
20 | public GraphicsContext(Graphics2D graphics2D, ScreenInfo screenInfo) { | ||
21 | this.graphics2D = Objects.requireNonNull(graphics2D); | ||
22 | this.screenInfo = Objects.requireNonNull(screenInfo); | ||
23 | } | ||
24 | |||
25 | /** | ||
26 | * @return the drawable canvas | ||
27 | */ | ||
28 | public Graphics2D getGraphics2D() { | ||
29 | return graphics2D; | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * @return the screen informations | ||
34 | */ | ||
35 | public ScreenInfo getScreenInfo() { | ||
36 | return screenInfo; | ||
37 | } | ||
5 | } | 38 | } |
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 142a8e8..2881da9 100644 --- a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java +++ b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java | |||
@@ -1,5 +1,58 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | public class InputHandler { | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.event.DropBombEvent; | ||
5 | import fr.umlv.java.wallj.event.MoveRobotEvent; | ||
6 | import fr.umlv.zen5.ApplicationContext; | ||
7 | import fr.umlv.zen5.Event; | ||
8 | import fr.umlv.zen5.KeyboardKey; | ||
9 | import org.jbox2d.common.Vec2; | ||
10 | |||
11 | import java.awt.geom.Point2D; | ||
12 | import java.util.LinkedList; | ||
13 | import java.util.List; | ||
14 | import java.util.Objects; | ||
15 | |||
16 | import static fr.umlv.java.wallj.board.TileVec2.of; | ||
17 | |||
18 | public final class InputHandler { | ||
4 | //TODO Class InputHandler | 19 | //TODO Class InputHandler |
20 | private final ApplicationContext applicationContext; | ||
21 | |||
22 | /** | ||
23 | * @param applicationContext | ||
24 | */ | ||
25 | public InputHandler(ApplicationContext applicationContext) { | ||
26 | this.applicationContext = Objects.requireNonNull(applicationContext); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @return | ||
31 | */ | ||
32 | List<fr.umlv.java.wallj.event.Event> getEvents() { | ||
33 | LinkedList<fr.umlv.java.wallj.event.Event> events = new LinkedList<>(); | ||
34 | fr.umlv.zen5.Event event = applicationContext.pollEvent(); | ||
35 | if (event != null) { | ||
36 | Event.Action action = event.getAction(); | ||
37 | Point2D.Float location = event.getLocation(); | ||
38 | if (location != null) { //Mouse Handling | ||
39 | if (action == Event.Action.POINTER_DOWN) { | ||
40 | Vec2 mouseLocation = new Vec2(location.x, location.y); | ||
41 | TileVec2 mouseTileLocation = TileVec2.of(mouseLocation); | ||
42 | events.add(new MoveRobotEvent(mouseTileLocation)); | ||
43 | } | ||
44 | } | ||
45 | KeyboardKey keyboardKey = event.getKey(); | ||
46 | if (keyboardKey != null) { //Keyboard Handling | ||