From 66ca4c453a6dc67e3b09ef3365c3b4805c44910d Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 20:33:17 +0100 Subject: Implementing Display controllers (and changing null in some Physics controllers to test the displays) --- .../umlv/java/wallj/controller/BombDisplayController.java | 14 ++++++++++++-- .../umlv/java/wallj/controller/BombPhysicsController.java | 3 ++- .../java/wallj/controller/GarbageDisplayController.java | 9 +++++++-- .../umlv/java/wallj/controller/RobotDisplayController.java | 9 +++++++-- .../umlv/java/wallj/controller/RobotPhysicsController.java | 3 ++- .../umlv/java/wallj/controller/TrashDisplayController.java | 9 +++++++-- .../umlv/java/wallj/controller/WallDisplayController.java | 2 +- 7 files changed, 38 insertions(+), 11 deletions(-) (limited to 'src/main/java/fr/umlv') diff --git a/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java index aa652a8..86a857f 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java @@ -1,9 +1,14 @@ package fr.umlv.java.wallj.controller; +import fr.umlv.java.wallj.board.TileVec2; import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.context.GraphicsContext; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.BombBlock; +import org.jbox2d.common.Vec2; +import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,8 +23,13 @@ public class BombDisplayController extends DisplayController { @Override public List update(Context context) { - //TODO - return null; + GraphicsContext graphicsContext = context.getGraphicsContext(); + graphicsContext.paintCircle(Color.BLACK, bomb.getPos(), TileVec2.TILE_DIM); + Vec2 textPosition = bomb.getPos(); + textPosition.x += TileVec2.TILE_DIM / 4.0f; + textPosition.y += 3 * TileVec2.TILE_DIM / 4.0f; + graphicsContext.paintString(Color.RED, textPosition, Integer.toString(bomb.getTimer())); + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java index 45a3626..ed7e520 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java @@ -4,6 +4,7 @@ import fr.umlv.java.wallj.context.Context; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.BombBlock; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -19,7 +20,7 @@ public class BombPhysicsController extends PhysicsController { @Override public List update(Context context) { //TODO - return null; + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java index e878fb2..e5e53ab 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java @@ -1,9 +1,13 @@ package fr.umlv.java.wallj.controller; +import fr.umlv.java.wallj.board.TileVec2; import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.context.GraphicsContext; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.GarbageBlock; +import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,8 +22,9 @@ public class GarbageDisplayController extends DisplayController { @Override public List update(Context context) { - //TODO - return null; + GraphicsContext graphicsContext = context.getGraphicsContext(); + graphicsContext.paintCircle(new Color(102, 51, 0), garbage.getPos(),TileVec2.TILE_DIM); + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java index 96ba68c..de3c4c4 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java @@ -1,9 +1,13 @@ package fr.umlv.java.wallj.controller; +import fr.umlv.java.wallj.board.TileVec2; import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.context.GraphicsContext; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.RobotBlock; +import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,8 +22,9 @@ public class RobotDisplayController extends DisplayController { @Override public List update(Context context) { - //TODO - return null; + GraphicsContext graphicsContext = context.getGraphicsContext(); + graphicsContext.paintCircle(Color.BLUE,robot.getPos(),TileVec2.TILE_DIM/2); + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java index f320480..57d098c 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java @@ -4,6 +4,7 @@ import fr.umlv.java.wallj.context.Context; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.RobotBlock; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -19,7 +20,7 @@ public class RobotPhysicsController extends PhysicsController { @Override public List update(Context context) { //TODO - return null; + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java index dfba9be..523528b 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java @@ -1,9 +1,13 @@ package fr.umlv.java.wallj.controller; +import fr.umlv.java.wallj.board.TileVec2; import fr.umlv.java.wallj.context.Context; +import fr.umlv.java.wallj.context.GraphicsContext; import fr.umlv.java.wallj.event.Event; import fr.umlv.java.wallj.model.TrashBlock; +import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,8 +22,9 @@ public class TrashDisplayController extends DisplayController { @Override public List update(Context context) { - //TODO - return null; + GraphicsContext graphicsContext = context.getGraphicsContext(); + graphicsContext.paintRectangle(Color.RED,trash.getPos(), TileVec2.TILE_DIM,TileVec2.TILE_DIM); + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java index 7b7011c..428f83c 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java @@ -23,7 +23,7 @@ public class WallDisplayController extends BlockController { @Override public List update(Context context) { GraphicsContext graphicsContext = context.getGraphicsContext(); - graphicsContext.paintRectangle(Color.GRAY,wall.getPos(), TileVec2.TILE_DIM,TileVec2.TILE_DIM); + graphicsContext.paintRectangle(Color.BLACK,wall.getPos(), TileVec2.TILE_DIM,TileVec2.TILE_DIM); return Collections.emptyList(); } -- cgit v1.2.3 From d1c6b2f6a9fe6af75f1668e25d96ec4380f69f76 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 20:35:08 +0100 Subject: Modifying implementation of paintCircle to center the cicle when it is smaller and implementing paintString to print text on screen --- src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/main/java/fr/umlv') 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 0475973..2c1c72a 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,6 @@ package fr.umlv.java.wallj.context; +import fr.umlv.java.wallj.board.TileVec2; import fr.umlv.zen5.ScreenInfo; import org.jbox2d.common.Vec2; @@ -47,7 +48,7 @@ public final class GraphicsContext { */ public void paintCircle(Color color, Vec2 position, float size) { graphics2D.setColor(color); - graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size)); + graphics2D.fillOval(Math.round(position.x + (TileVec2.TILE_DIM - size) / 2) - 1, Math.round(position.y + (TileVec2.TILE_DIM - size) / 2) - 1, Math.round(size), Math.round(size)); } /** @@ -58,6 +59,11 @@ public final class GraphicsContext { */ 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)); + graphics2D.fillRect(Math.round(position.x), Math.round(position.y), Math.round(width), Math.round(height)); + } + + public void paintString(Color color, Vec2 position, String string){ + graphics2D.setColor(color); + graphics2D.drawString(string,position.x, position.y); } } -- cgit v1.2.3 From c0dbbdc990a68a99b2d913bba9698d7e0894e924 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 22:48:02 +0100 Subject: Modifying the implementation of the Main, with Validation feature and exception handling --- src/main/java/fr/umlv/java/wallj/Main.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/main/java/fr/umlv') diff --git a/src/main/java/fr/umlv/java/wallj/Main.java b/src/main/java/fr/umlv/java/wallj/Main.java index 3b3ad54..0ac4136 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java @@ -2,6 +2,7 @@ package fr.umlv.java.wallj; import fr.umlv.java.wallj.board.Board; import fr.umlv.java.wallj.board.BoardParser; +import fr.umlv.java.wallj.board.BoardValidator; import fr.umlv.java.wallj.viewer.Viewer; import fr.umlv.zen5.Application; @@ -32,20 +33,31 @@ public class Main { } public static void main(String[] args) { - java.util.List boards = new LinkedList<>(); + List boards = new LinkedList<>(); try { List boardPaths = Main.getResourcePaths(args); for (Path path : boardPaths) { - boards.add(BoardParser.parse(path)); + BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); + boards.add( + boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") + .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") + .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") + .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") + .get()); } Viewer viewer = new Viewer(boards); - Application.run(Color.BLACK, viewer::eventLoop); + Application.run(Color.WHITE, viewer::eventLoop); } catch (URISyntaxException e) { System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(2); + } catch (BoardValidator.ValidationException e) { + for (Throwable throwable : e.getSuppressed()) { + System.err.println(throwable.getMessage()); + } + System.exit(3); } } } -- cgit v1.2.3