diff options
author | pacien | 2018-01-14 18:14:23 +0100 |
---|---|---|
committer | pacien | 2018-01-14 18:14:23 +0100 |
commit | 7c527484ef4834a14e21277d33f8c490d967087b (patch) | |
tree | 19f1c1a5fd87143dba764deff88e0db27f972fdd /src/main/java/fr/umlv | |
parent | 1f161aae93903dc8747f5a16c4d86cfccea6698b (diff) | |
parent | d9b09855d3f367eb1eeab0a809f646d4eca201f0 (diff) | |
download | wallj-7c527484ef4834a14e21277d33f8c490d967087b.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
Diffstat (limited to 'src/main/java/fr/umlv')
5 files changed, 92 insertions, 26 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/Main.java b/src/main/java/fr/umlv/java/wallj/Main.java index 7511980..3b3ad54 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 @@ | |||
1 | package fr.umlv.java.wallj; | 1 | package fr.umlv.java.wallj; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | ||
4 | import fr.umlv.java.wallj.board.BoardParser; | ||
5 | import fr.umlv.java.wallj.viewer.Viewer; | ||
3 | import fr.umlv.zen5.Application; | 6 | import fr.umlv.zen5.Application; |
4 | 7 | ||
5 | import java.awt.*; | 8 | import java.awt.*; |
9 | import java.io.IOException; | ||
10 | import java.net.URISyntaxException; | ||
11 | import java.nio.file.Path; | ||
12 | import java.nio.file.Paths; | ||
13 | import java.util.LinkedList; | ||
14 | import java.util.List; | ||
6 | 15 | ||
7 | public class Main { | 16 | public class Main { |
8 | 17 | ||
9 | /** | 18 | private static Path getResourcePath(String str) throws URISyntaxException { |
10 | * Dummy entry point. | 19 | return Paths.get(Main.class.getResource(str).toURI()); |
11 | * | 20 | } |
12 | * @param args no need to argue | 21 | |
13 | */ | 22 | private static java.util.List<Path> getResourcePaths(String[] args) throws URISyntaxException { |
14 | public static void main(String[] args) { | 23 | LinkedList<Path> paths = new LinkedList<>(); |
15 | System.out.println("Hello World!"); | 24 | if (args.length > 0) { |
16 | Application.run(Color.BLACK, (ac) -> { | 25 | for (String string : args) { |
17 | }); | 26 | paths.add(Paths.get(string)); |
27 | } | ||
28 | } else { | ||
29 | paths.add(getResourcePath("/maps/smallvalid.txt")); | ||
30 | } | ||
31 | return paths; | ||
18 | } | 32 | } |
19 | 33 | ||
34 | public static void main(String[] args) { | ||
35 | java.util.List<Board> boards = new LinkedList<>(); | ||
36 | try { | ||
37 | List<Path> boardPaths = Main.getResourcePaths(args); | ||
38 | for (Path path : boardPaths) { | ||
39 | boards.add(BoardParser.parse(path)); | ||
40 | } | ||
41 | Viewer viewer = new Viewer(boards); | ||
42 | Application.run(Color.BLACK, viewer::eventLoop); | ||
43 | } catch (URISyntaxException e) { | ||
44 | System.err.println(e.getMessage()); | ||
45 | System.exit(1); | ||
46 | } catch (IOException e) { | ||
47 | System.err.println(e.getMessage()); | ||
48 | System.exit(2); | ||
49 | } | ||
50 | } | ||
20 | } | 51 | } |
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 82200a7..1d95690 100644 --- a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java +++ b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java | |||
@@ -14,7 +14,7 @@ import java.util.stream.Collectors; | |||
14 | */ | 14 | */ |
15 | public final class TileVec2 { | 15 | public final class TileVec2 { |
16 | 16 | ||
17 | private static final int TILE_DIM = 20; | 17 | public static final int TILE_DIM = 20; |
18 | private static final List<TileVec2> NEIGHBOR_OFFSETS = Arrays.asList( | 18 | private static final List<TileVec2> NEIGHBOR_OFFSETS = Arrays.asList( |
19 | of(0, -1), | 19 | of(0, -1), |
20 | of(-1, 0), | 20 | of(-1, 0), |
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 @@ | |||
1 | package fr.umlv.java.wallj.controller; | 1 | package fr.umlv.java.wallj.controller; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | ||
3 | import fr.umlv.java.wallj.context.Context; | 4 | import fr.umlv.java.wallj.context.Context; |
5 | import fr.umlv.java.wallj.context.GraphicsContext; | ||
4 | import fr.umlv.java.wallj.event.Event; | 6 | import fr.umlv.java.wallj.event.Event; |
5 | import fr.umlv.java.wallj.model.WallBlock; | 7 | import fr.umlv.java.wallj.model.WallBlock; |
6 | 8 | ||
9 | import java.awt.*; | ||
10 | import java.util.Collections; | ||
7 | import java.util.List; | 11 | import java.util.List; |
8 | import java.util.Objects; | 12 | import java.util.Objects; |
9 | 13 | ||
@@ -18,8 +22,9 @@ public class WallDisplayController extends BlockController { | |||
18 | 22 | ||
19 | @Override | 23 | @Override |
20 | public List<Event> update(Context context) { | 24 | public List<Event> update(Context context) { |
21 | //TODO | 25 | GraphicsContext graphicsContext = context.getGraphicsContext(); |
22 | return null; | 26 | graphicsContext.paintRectangle(Color.GRAY,wall.getPos(), TileVec2.TILE_DIM,TileVec2.TILE_DIM); |
27 | return Collections.emptyList(); | ||
23 | } | 28 | } |
24 | 29 | ||
25 | } | 30 | } |
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; | |||
4 | import fr.umlv.java.wallj.event.Event; | 4 | import fr.umlv.java.wallj.event.Event; |
5 | import fr.umlv.java.wallj.model.WallBlock; | 5 | import fr.umlv.java.wallj.model.WallBlock; |
6 | 6 | ||
7 | import java.util.Collections; | ||
7 | import java.util.List; | 8 | import java.util.List; |
8 | import java.util.Objects; | 9 | import java.util.Objects; |
9 | 10 | ||
@@ -19,7 +20,7 @@ public class WallPhysicsController extends PhysicsController { | |||
19 | @Override | 20 | @Override |
20 | public List<Event> update(Context context) { | 21 | public List<Event> update(Context context) { |
21 | //TODO | 22 | //TODO |
22 | return null; | 23 | return Collections.emptyList(); |
23 | } | 24 | } |
24 | 25 | ||
25 | } | 26 | } |
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 @@ | |||
1 | package fr.umlv.java.wallj.viewer; | 1 | package fr.umlv.java.wallj.viewer; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | ||
4 | import fr.umlv.java.wallj.board.BoardParser; | ||
5 | import fr.umlv.java.wallj.board.BoardValidator; | ||
6 | import fr.umlv.java.wallj.context.Context; | ||
7 | import fr.umlv.java.wallj.context.Game; | ||
8 | import fr.umlv.java.wallj.context.InputHandler; | ||
9 | import fr.umlv.java.wallj.context.ScreenManager; | ||
10 | import fr.umlv.java.wallj.event.Event; | ||
11 | import fr.umlv.zen5.Application; | ||
3 | import fr.umlv.zen5.ApplicationContext; | 12 | import fr.umlv.zen5.ApplicationContext; |
13 | import sun.awt.image.ImageWatched; | ||
4 | 14 | ||
5 | import java.awt.*; | 15 | import java.awt.*; |
16 | import java.io.IOException; | ||
17 | import java.net.URISyntaxException; | ||
18 | import java.nio.file.Path; | ||
19 | import java.nio.file.Paths; | ||
20 | import java.util.LinkedList; | ||
21 | import java.util.List; | ||
22 | import java.util.Objects; | ||
6 | 23 | ||
7 | /** | 24 | /** |
8 | * Link between application and Zen 5 | 25 | * Link between application and Zen 5 |
9 | */ | 26 | */ |
10 | public class Viewer { | 27 | public 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<...> |