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') 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