From eeda506af16c3da6619e0a8a4941b41a640fe616 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 16:36:03 +0100 Subject: Implementing Viewer --- .../java/fr/umlv/java/wallj/viewer/Viewer.java | 55 +++++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'src/main/java/fr/umlv') 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 4ff432c..a87f418 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Viewer.java @@ -1,34 +1,63 @@ package fr.umlv.java.wallj.viewer; +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.context.Context; +import fr.umlv.java.wallj.context.Game; +import fr.umlv.java.wallj.context.InputHandler; +import fr.umlv.java.wallj.context.ScreenManager; +import fr.umlv.java.wallj.event.Event; +import fr.umlv.zen5.Application; import fr.umlv.zen5.ApplicationContext; +import sun.awt.image.ImageWatched; import java.awt.*; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; /** * Link between application and Zen 5 */ -public class Viewer { - - public static void main(String[] strings) { +public final class Viewer { + private final Game currentGame; + /** + * @param boards the valid list of boards charged in the application + */ + public Viewer(List boards) { + this.currentGame = new Game(Objects.requireNonNull(boards)); } /** - * * @param applicationContext the application context from Zen 5 */ - public static void eventLoop(ApplicationContext applicationContext) { - //TODO lambda exp for Application.run(Consumer<...>) - //usage : Viewer::eventLoop + public void eventLoop(ApplicationContext applicationContext) { + List events = new LinkedList<>(); + while (!currentGame.isOver()) { + applicationContext.renderFrame(graphics2D -> { + events.addAll(renderFrame(graphics2D, applicationContext, events)); //add the new events returned by updates + }); + } } /** - * - * @param graphics2D the graphic2D from Zen 5 + * @param graphics2D the graphic2D from Zen 5 * @param applicationContext the application context from Zen 5 */ - public static void renderFrame(Graphics2D graphics2D,ApplicationContext applicationContext) { - //TODO lambda exp for ApplicationContext.renderFrame(Consumer<...>) - //usage : graphics->Viewer.renderFrame(graphics2D,applicationContext) + public List renderFrame(Graphics2D graphics2D, ApplicationContext applicationContext, List events) { + InputHandler inputHandler = new InputHandler(applicationContext); + ScreenManager screenManager = new ScreenManager(applicationContext, graphics2D); + events.addAll(inputHandler.getEvents()); + Context context = new Context(currentGame, events, screenManager.clearScreen()); + List newEvents = currentGame.update(context); //return new events created from update(); + events.clear(); + return newEvents; } -} \ No newline at end of file +} + -- cgit v1.2.3 From 7978145be5557b26999766e24978735c1c701e2a Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 16:37:42 +0100 Subject: Implementing the beginning of parsing thing, call to application.run() --- src/main/java/fr/umlv/java/wallj/Main.java | 49 ++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 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 7511980..4f35aab 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java @@ -1,20 +1,51 @@ package fr.umlv.java.wallj; +import fr.umlv.java.wallj.board.Board; +import fr.umlv.java.wallj.board.BoardParser; +import fr.umlv.java.wallj.viewer.Viewer; import fr.umlv.zen5.Application; import java.awt.*; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.LinkedList; +import java.util.List; public class Main { - /** - * Dummy entry point. - * - * @param args no need to argue - */ - public static void main(String[] args) { - System.out.println("Hello World!"); - Application.run(Color.BLACK, (ac) -> { - }); + private static Path getResourcePath(String str) throws URISyntaxException { + return Paths.get(Main.class.getResource(str).toURI()); + } + + private static java.util.List getResourcePaths(String[] args) throws URISyntaxException { + LinkedList paths = new LinkedList<>(); + if (args.length > 0) { + for (String string : args) { + paths.add(Paths.get(string)); + } + } else { + paths.add(getResourcePath("/maps/smallvalid.txt")); + } + return paths; } + public static void main(String[] args) { + java.util.List boards = new LinkedList<>(); + try { + List boardPaths = Main.getResourcePaths(args); + for (Path path : boardPaths) { + boards.add(BoardParser.parse(path)); + } + Viewer viewer = new Viewer(boards); + Application.run(Color.BLACK, viewer::eventLoop); + } catch (URISyntaxException e) { + System.err.println("Error in path syntax."); + System.exit(1); + } catch (IOException e) { + System.err.println("Something occurred while reading the files."); + System.exit(1); + } + } } -- cgit v1.2.3 From 532b0b39e4468baaeb5c79defd76eee447d58bc9 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 16:38:56 +0100 Subject: Modifying the accessibility of the constant of size in TileVec2 (used to display) --- src/main/java/fr/umlv/java/wallj/board/TileVec2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/fr/umlv') diff --git a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java index 70beed9..4e8fa55 100644 --- a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java +++ b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java @@ -11,7 +11,7 @@ import java.util.Objects; */ public final class TileVec2 { - private static final int TILE_DIM = 20; + public static final int TILE_DIM = 20; /** * @param col the column -- cgit v1.2.3 From cbab6f20fe6cd2eaa8ae41c815612a32db3b11bb Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 18:04:29 +0100 Subject: Modifying Exception handling messages in Main --- src/main/java/fr/umlv/java/wallj/Main.java | 6 +++--- 1 file changed, 3 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 4f35aab..3b3ad54 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java @@ -41,11 +41,11 @@ public class Main { Viewer viewer = new Viewer(boards); Application.run(Color.BLACK, viewer::eventLoop); } catch (URISyntaxException e) { - System.err.println("Error in path syntax."); + System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { - System.err.println("Something occurred while reading the files."); - System.exit(1); + System.err.println(e.getMessage()); + System.exit(2); } } } -- cgit v1.2.3 From d9b09855d3f367eb1eeab0a809f646d4eca201f0 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 18:06:46 +0100 Subject: Implementing Wall controllers for a not committed test of GUI --- .../fr/umlv/java/wallj/controller/WallDisplayController.java | 9 +++++++-- .../fr/umlv/java/wallj/controller/WallPhysicsController.java | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main/java/fr/umlv') 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 3700acb..7b7011c 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.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.WallBlock; +import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,8 +22,9 @@ public class WallDisplayController extends BlockController { @Override public List update(Context context) { - //TODO - return null; + GraphicsContext graphicsContext = context.getGraphicsContext(); + graphicsContext.paintRectangle(Color.GRAY,wall.getPos(), TileVec2.TILE_DIM,TileVec2.TILE_DIM); + return Collections.emptyList(); } } diff --git a/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java b/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java index 146ca34..3fb00bb 100644 --- a/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.java +++ b/src/main/java/fr/umlv/java/wallj/controller/WallPhysicsController.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.WallBlock; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -19,7 +20,7 @@ public class WallPhysicsController extends PhysicsController { @Override public List update(Context context) { //TODO - return null; + return Collections.emptyList(); } } -- cgit v1.2.3