aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv
diff options
context:
space:
mode:
authorAdam NAILI2018-01-14 16:36:03 +0100
committerAdam NAILI2018-01-14 16:36:03 +0100
commiteeda506af16c3da6619e0a8a4941b41a640fe616 (patch)
treec1efe062d13c86c293eb485e2a6df749e460242e /src/main/java/fr/umlv
parent41b33fb7ffd4c901557f25c972df2e9175e75d4f (diff)
downloadwallj-eeda506af16c3da6619e0a8a4941b41a640fe616.tar.gz
Implementing Viewer
Diffstat (limited to 'src/main/java/fr/umlv')
-rw-r--r--src/main/java/fr/umlv/java/wallj/viewer/Viewer.java55
1 files changed, 42 insertions, 13 deletions
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 @@
1package fr.umlv.java.wallj.viewer; 1package fr.umlv.java.wallj.viewer;
2 2
3import fr.umlv.java.wallj.board.Board;
4import fr.umlv.java.wallj.board.BoardParser;
5import fr.umlv.java.wallj.board.BoardValidator;
6import fr.umlv.java.wallj.context.Context;
7import fr.umlv.java.wallj.context.Game;
8import fr.umlv.java.wallj.context.InputHandler;
9import fr.umlv.java.wallj.context.ScreenManager;
10import fr.umlv.java.wallj.event.Event;
11import fr.umlv.zen5.Application;
3import fr.umlv.zen5.ApplicationContext; 12import fr.umlv.zen5.ApplicationContext;
13import sun.awt.image.ImageWatched;
4 14
5import java.awt.*; 15import java.awt.*;
16import java.io.IOException;
17import java.net.URISyntaxException;
18import java.nio.file.Path;
19import java.nio.file.Paths;
20import java.util.LinkedList;
21import java.util.List;
22import java.util.Objects;
6 23
7/** 24/**
8 * Link between application and Zen 5 25 * Link between application and Zen 5
9 */ 26 */
10public class Viewer { 27public final class Viewer {
11
12 public static void main(String[] strings) {
13 28
29 private final Game currentGame;
30 /**
31 * @param boards the valid list of boards charged in the application
32 */
33 public Viewer(List<Board> boards) {
34 this.currentGame = new Game(Objects.requireNonNull(boards));
14 } 35 }
15 36
16 /** 37 /**
17 *
18 * @param applicationContext the application context from Zen 5 38 * @param applicationContext the application context from Zen 5
19 */ 39 */
20 public static void eventLoop(ApplicationContext applicationContext) { 40 public void eventLoop(ApplicationContext applicationContext) {
21 //TODO lambda exp for Application.run(Consumer<...>) 41 List<Event> events = new LinkedList<>();
22 //usage : Viewer::eventLoop 42 while (!currentGame.isOver()) {
43 applicationContext.renderFrame(graphics2D -> {
44 events.addAll(renderFrame(graphics2D, applicationContext, events)); //add the new events returned by updates
45 });
46 }
23 } 47 }
24 48
25 /** 49 /**
26 * 50 * @param graphics2D the graphic2D from Zen 5
27 * @param graphics2D the graphic2D from Zen 5
28 * @param applicationContext the application context from Zen 5 51 * @param applicationContext the application context from Zen 5
29 */ 52 */
30 public static void renderFrame(Graphics2D graphics2D,ApplicationContext applicationContext) { 53 public List<Event> renderFrame(Graphics2D graphics2D, ApplicationContext applicationContext, List<Event> events) {
31 //TODO lambda exp for ApplicationContext.renderFrame(Consumer<...>) 54 InputHandler inputHandler = new InputHandler(applicationContext);
32 //usage : graphics->Viewer.renderFrame(graphics2D,applicationContext) 55 ScreenManager screenManager = new ScreenManager(applicationContext, graphics2D);
56 events.addAll(inputHandler.getEvents());
57 Context context = new Context(currentGame, events, screenManager.clearScreen());
58 List<Event> newEvents = currentGame.update(context); //return new events created from update();
59 events.clear();
60 return newEvents;
33 } 61 }
34} \ No newline at end of file 62}
63