aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAdam NAILI2018-01-09 01:26:23 +0100
committerAdam NAILI2018-01-09 01:26:23 +0100
commitb0335642307ee51c9f3153194e1f43126e278c4b (patch)
tree7685db0d419c2e71fd5284594ce4e94e9ade1ca8 /src/main/java
parentf43e7c1c1ddc182762ce8173c72d78f18dc4d58c (diff)
downloadwallj-b0335642307ee51c9f3153194e1f43126e278c4b.tar.gz
Implementing classes from context package (Context, Game, GraphicsContext, InputHandler, ScreenManager)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Context.java2
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Game.java2
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java28
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/InputHandler.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/ScreenManager.java35
5 files changed, 67 insertions, 8 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 a924c2b..1f188de 100644
--- a/src/main/java/fr/umlv/java/wallj/context/Context.java
+++ b/src/main/java/fr/umlv/java/wallj/context/Context.java
@@ -7,7 +7,7 @@ import java.util.List;
7import java.util.Objects; 7import java.util.Objects;
8 8
9/** 9/**
10 * A context used to store the current state of the application at one tick. 10 * A context used to store the current state of the application at one tick
11 */ 11 */
12public final class Context { 12public final class Context {
13 //TODO Class Context 13 //TODO Class Context
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 b3418c4..ba7cb58 100644
--- a/src/main/java/fr/umlv/java/wallj/context/Game.java
+++ b/src/main/java/fr/umlv/java/wallj/context/Game.java
@@ -9,7 +9,7 @@ import java.util.NoSuchElementException;
9import java.util.Objects; 9import java.util.Objects;
10 10
11/** 11/**
12 * A game 12 * A game.
13 */ 13 */
14public final class Game { 14public final class Game {
15 //TODO 15 //TODO
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 214eeb0..46c326a 100644
--- a/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java
+++ b/src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java
@@ -1,12 +1,15 @@
1package fr.umlv.java.wallj.context; 1package fr.umlv.java.wallj.context;
2 2
3import fr.umlv.zen5.ScreenInfo; 3import fr.umlv.zen5.ScreenInfo;
4import org.jbox2d.common.Vec2;
4 5
5import java.awt.Graphics2D; 6import java.awt.*;
7import java.awt.geom.Ellipse2D;
8import java.awt.geom.Rectangle2D;
6import java.util.Objects; 9import java.util.Objects;
7 10
8/** 11/**
9 * A context of the current graphic status of the application 12 * A context of the current graphic status of the application.
10 */ 13 */
11public final class GraphicsContext { 14public final class GraphicsContext {
12 //TODO Class GraphicsContext 15 //TODO Class GraphicsContext
@@ -35,4 +38,25 @@ public final class GraphicsContext {
35 public ScreenInfo getScreenInfo() { 38 public ScreenInfo getScreenInfo() {
36 return screenInfo; 39 return screenInfo;
37 } 40 }
41
42 /**
43 * @param color the color of the circle
44 * @param position the upper left corner of the rectangle frame that contains the circle
45 * @param size size of the circle
46 */
47 public void paintCircle(Color color, Vec2 position, float size) {
48 graphics2D.setColor(color);
49 graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size));
50 }
51
52 /**
53 * @param color the color of the rectangle
54 * @param position the upper left corner of the rectangle
55 * @param width width of the rectangle
56 * @param height height of the rectangle
57 */
58 public void paintRectangle(Color color, Vec2 position, float width, float height) {
59 graphics2D.setColor(color);
60 graphics2D.fill(new Rectangle2D.Float(position.x, position.y, width, height));
61 }
38} 62}
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 2881da9..171f665 100644
--- a/src/main/java/fr/umlv/java/wallj/context/InputHandler.java
+++ b/src/main/java/fr/umlv/java/wallj/context/InputHandler.java
@@ -13,21 +13,23 @@ import java.util.LinkedList;
13import java.util.List; 13import java.util.List;
14import java.util.Objects; 14import java.util.Objects;
15 15
16import static fr.umlv.java.wallj.board.TileVec2.of;
17 16
17/**
18 * Treats the inputs from the keyboard and mouse provided by Zen 5 and creates Events meaningful for the game.
19 */
18public final class InputHandler { 20public final class InputHandler {
19 //TODO Class InputHandler 21 //TODO Class InputHandler
20 private final ApplicationContext applicationContext; 22 private final ApplicationContext applicationContext;
21 23
22 /** 24 /**
23 * @param applicationContext 25 * @param applicationContext the Zen5 application context
24 */ 26 */
25 public InputHandler(ApplicationContext applicationContext) { 27 public InputHandler(ApplicationContext applicationContext) {
26 this.applicationContext = Objects.requireNonNull(applicationContext); 28 this.applicationContext = Objects.requireNonNull(applicationContext);
27 } 29 }
28 30
29 /** 31 /**
30 * @return 32 * @return the list of events converted from Zen 5 events to game events
31 */ 33 */
32 List<fr.umlv.java.wallj.event.Event> getEvents() { 34 List<fr.umlv.java.wallj.event.Event> getEvents() {
33 LinkedList<fr.umlv.java.wallj.event.Event> events = new LinkedList<>(); 35 LinkedList<fr.umlv.java.wallj.event.Event> events = new LinkedList<>();
diff --git a/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java b/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java
index 4587355..9d6255f 100644
--- a/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java
+++ b/src/main/java/fr/umlv/java/wallj/context/ScreenManager.java
@@ -1,5 +1,38 @@
1package fr.umlv.java.wallj.context; 1package fr.umlv.java.wallj.context;
2 2
3public class ScreenManager { 3import fr.umlv.zen5.ApplicationContext;
4import fr.umlv.zen5.ScreenInfo;
5import org.jbox2d.common.Vec2;
6
7import java.awt.Graphics2D;
8import java.util.Objects;
9
10/**
11 * Cleans the GraphicsContext
12 */
13public final class ScreenManager {
4 //TODO Class ScreenManager 14 //TODO Class ScreenManager
15 private final ApplicationContext applicationContext;
16 private final Graphics2D graphics2D;
17
18 /**
19 *
20 * @param applicationContext the current application context
21 * @param graphics2D the current graphics2D
22 */
23 public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) {
24 this.applicationContext = Objects.requireNonNull(applicationContext);
25 this.graphics2D = Objects.requireNonNull(graphics2D);
26 }
27
28 /**
29 *
30 * @return a graphic context
31 */
32 public GraphicsContext clearScreen() {
33 ScreenInfo screenInfo = applicationContext.getScreenInfo();
34 GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo);
35 graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight());
36 return graphicsContext;
37 }
5} 38}