From b0335642307ee51c9f3153194e1f43126e278c4b Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 9 Jan 2018 01:26:23 +0100 Subject: Implementing classes from context package (Context, Game, GraphicsContext, InputHandler, ScreenManager) --- .../java/fr/umlv/java/wallj/context/Context.java | 2 +- src/main/java/fr/umlv/java/wallj/context/Game.java | 2 +- .../umlv/java/wallj/context/GraphicsContext.java | 28 +++++++++++++++-- .../fr/umlv/java/wallj/context/InputHandler.java | 8 +++-- .../fr/umlv/java/wallj/context/ScreenManager.java | 35 +++++++++++++++++++++- 5 files changed, 67 insertions(+), 8 deletions(-) (limited to 'src/main/java') 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; import java.util.Objects; /** - * A context used to store the current state of the application at one tick. + * A context used to store the current state of the application at one tick */ public final class Context { //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; import java.util.Objects; /** - * A game + * A game. */ public final class Game { //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 @@ package fr.umlv.java.wallj.context; import fr.umlv.zen5.ScreenInfo; +import org.jbox2d.common.Vec2; -import java.awt.Graphics2D; +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Rectangle2D; import java.util.Objects; /** - * A context of the current graphic status of the application + * A context of the current graphic status of the application. */ public final class GraphicsContext { //TODO Class GraphicsContext @@ -35,4 +38,25 @@ public final class GraphicsContext { public ScreenInfo getScreenInfo() { return screenInfo; } + + /** + * @param color the color of the circle + * @param position the upper left corner of the rectangle frame that contains the circle + * @param size size of the circle + */ + public void paintCircle(Color color, Vec2 position, float size) { + graphics2D.setColor(color); + graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size)); + } + + /** + * @param color the color of the rectangle + * @param position the upper left corner of the rectangle + * @param width width of the rectangle + * @param height height of the rectangle + */ + public void paintRectangle(Color color, Vec2 position, float width, float height) { + graphics2D.setColor(color); + graphics2D.fill(new Rectangle2D.Float(position.x, position.y, width, height)); + } } 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; import java.util.List; import java.util.Objects; -import static fr.umlv.java.wallj.board.TileVec2.of; +/** + * Treats the inputs from the keyboard and mouse provided by Zen 5 and creates Events meaningful for the game. + */ public final class InputHandler { //TODO Class InputHandler private final ApplicationContext applicationContext; /** - * @param applicationContext + * @param applicationContext the Zen5 application context */ public InputHandler(ApplicationContext applicationContext) { this.applicationContext = Objects.requireNonNull(applicationContext); } /** - * @return + * @return the list of events converted from Zen 5 events to game events */ List getEvents() { LinkedList 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 @@ package fr.umlv.java.wallj.context; -public class ScreenManager { +import fr.umlv.zen5.ApplicationContext; +import fr.umlv.zen5.ScreenInfo; +import org.jbox2d.common.Vec2; + +import java.awt.Graphics2D; +import java.util.Objects; + +/** + * Cleans the GraphicsContext + */ +public final class ScreenManager { //TODO Class ScreenManager + private final ApplicationContext applicationContext; + private final Graphics2D graphics2D; + + /** + * + * @param applicationContext the current application context + * @param graphics2D the current graphics2D + */ + public ScreenManager(ApplicationContext applicationContext, Graphics2D graphics2D) { + this.applicationContext = Objects.requireNonNull(applicationContext); + this.graphics2D = Objects.requireNonNull(graphics2D); + } + + /** + * + * @return a graphic context + */ + public GraphicsContext clearScreen() { + ScreenInfo screenInfo = applicationContext.getScreenInfo(); + GraphicsContext graphicsContext = new GraphicsContext(graphics2D, screenInfo); + graphicsContext.paintRectangle(graphics2D.getBackground(), new Vec2(0, 0), screenInfo.getWidth(), screenInfo.getHeight()); + return graphicsContext; + } } -- cgit v1.2.3