diff options
author | pacien | 2018-01-14 23:11:42 +0100 |
---|---|---|
committer | pacien | 2018-01-14 23:11:42 +0100 |
commit | 12c9d15bc951dbc80832104f68e5c6e140bdb770 (patch) | |
tree | af3c51dd10ff06564eb5b29eba5e1f48ef8e5eea /src/main/java/fr/umlv | |
parent | 0a73db0e47a93dcf70be2ed75cd64e1762ae316c (diff) | |
parent | c0dbbdc990a68a99b2d913bba9698d7e0894e924 (diff) | |
download | wallj-12c9d15bc951dbc80832104f68e5c6e140bdb770.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-java-wallj
Signed-off-by: pacien <pacien.trangirard@pacien.net>
# Conflicts:
# src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java
Diffstat (limited to 'src/main/java/fr/umlv')
9 files changed, 61 insertions, 16 deletions
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; | |||
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | 3 | import fr.umlv.java.wallj.board.Board; |
4 | import fr.umlv.java.wallj.board.BoardParser; | 4 | import fr.umlv.java.wallj.board.BoardParser; |
5 | import fr.umlv.java.wallj.board.BoardValidator; | ||
5 | import fr.umlv.java.wallj.viewer.Viewer; | 6 | import fr.umlv.java.wallj.viewer.Viewer; |
6 | import fr.umlv.zen5.Application; | 7 | import fr.umlv.zen5.Application; |
7 | 8 | ||
@@ -32,20 +33,31 @@ public class Main { | |||
32 | } | 33 | } |
33 | 34 | ||
34 | public static void main(String[] args) { | 35 | public static void main(String[] args) { |
35 | java.util.List<Board> boards = new LinkedList<>(); | 36 | List<Board> boards = new LinkedList<>(); |
36 | try { | 37 | try { |
37 | List<Path> boardPaths = Main.getResourcePaths(args); | 38 | List<Path> boardPaths = Main.getResourcePaths(args); |
38 | for (Path path : boardPaths) { | 39 | for (Path path : boardPaths) { |
39 | boards.add(BoardParser.parse(path)); | 40 | BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); |
41 | boards.add( | ||
42 | boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") | ||
43 | .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") | ||
44 | .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") | ||
45 | .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") | ||
46 | .get()); | ||
40 | } | 47 | } |
41 | Viewer viewer = new Viewer(boards); | 48 | Viewer viewer = new Viewer(boards); |
42 | Application.run(Color.BLACK, viewer::eventLoop); | 49 | Application.run(Color.WHITE, viewer::eventLoop); |
43 | } catch (URISyntaxException e) { | 50 | } catch (URISyntaxException e) { |
44 | System.err.println(e.getMessage()); | 51 | System.err.println(e.getMessage()); |
45 | System.exit(1); | 52 | System.exit(1); |
46 | } catch (IOException e) { | 53 | } catch (IOException e) { |
47 | System.err.println(e.getMessage()); | 54 | System.err.println(e.getMessage()); |
48 | System.exit(2); | 55 | System.exit(2); |
56 | } catch (BoardValidator.ValidationException e) { | ||
57 | for (Throwable throwable : e.getSuppressed()) { | ||
58 | System.err.println(throwable.getMessage()); | ||
59 | } | ||
60 | System.exit(3); | ||
49 | } | 61 | } |
50 | } | 62 | } |
51 | } | 63 | } |
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 @@ | |||
1 | package fr.umlv.java.wallj.context; | 1 | package fr.umlv.java.wallj.context; |
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | ||
3 | import fr.umlv.zen5.ScreenInfo; | 4 | import fr.umlv.zen5.ScreenInfo; |
4 | import org.jbox2d.common.Vec2; | 5 | import org.jbox2d.common.Vec2; |
5 | 6 | ||
@@ -47,7 +48,7 @@ public final class GraphicsContext { | |||
47 | */ | 48 | */ |
48 | public void paintCircle(Color color, Vec2 position, float size) { | 49 | public void paintCircle(Color color, Vec2 position, float size) { |
49 | graphics2D.setColor(color); | 50 | graphics2D.setColor(color); |
50 | graphics2D.fill(new Ellipse2D.Float(position.x, position.y, size, size)); | 51 | 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)); |
51 | } | 52 | } |
52 | 53 | ||
53 | /** | 54 | /** |
@@ -58,6 +59,11 @@ public final class GraphicsContext { | |||
58 | */ | 59 | */ |
59 | public void paintRectangle(Color color, Vec2 position, float width, float height) { | 60 | public void paintRectangle(Color color, Vec2 position, float width, float height) { |
60 | graphics2D.setColor(color); | 61 | graphics2D.setColor(color); |
61 | graphics2D.fill(new Rectangle2D.Float(position.x, position.y, width, height)); | 62 | graphics2D.fillRect(Math.round(position.x), Math.round(position.y), Math.round(width), Math.round(height)); |
63 | } | ||
64 | |||
65 | public void paintString(Color color, Vec2 position, String string){ | ||
66 | graphics2D.setColor(color); | ||
67 | graphics2D.drawString(string,position.x, position.y); | ||
62 | } | 68 | } |
63 | } | 69 | } |
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 5a4964d..0c067e1 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 @@ | |||
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.block.BombBlock; | 7 | import fr.umlv.java.wallj.block.BombBlock; |
8 | import org.jbox2d.common.Vec2; | ||
6 | 9 | ||
10 | import java.awt.*; | ||
11 | import java.util.Collections; | ||
7 | import java.util.List; | 12 | import java.util.List; |
8 | import java.util.Objects; | 13 | import java.util.Objects; |
9 | 14 | ||
@@ -18,8 +23,13 @@ public class BombDisplayController extends DisplayController { | |||
18 | 23 | ||
19 | @Override | 24 | @Override |
20 | public List<Event> update(Context context) { | 25 | public List<Event> update(Context context) { |
21 | //TODO | 26 | GraphicsContext graphicsContext = context.getGraphicsContext(); |
22 | return null; | 27 | graphicsContext.paintCircle(Color.BLACK, bomb.getPos(), TileVec2.TILE_DIM); |
28 | Vec2 textPosition = bomb.getPos(); | ||
29 | textPosition.x += TileVec2.TILE_DIM / 4.0f; | ||
30 | textPosition.y += 3 * TileVec2.TILE_DIM / 4.0f; | ||
31 | graphicsContext.paintString(Color.RED, textPosition, Integer.toString(bomb.getTimer())); | ||
32 | return Collections.emptyList(); | ||
23 | } | 33 | } |
24 | 34 | ||
25 | } | 35 | } |
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 40ee550..2a7c44a 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; | |||
4 | import fr.umlv.java.wallj.event.Event; | 4 | import fr.umlv.java.wallj.event.Event; |
5 | import fr.umlv.java.wallj.block.BombBlock; | 5 | import fr.umlv.java.wallj.block.BombBlock; |
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 BombPhysicsController 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/controller/GarbageDisplayController.java b/src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java index 4dd7d70..8951d16 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 @@ | |||
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.block.GarbageBlock; | 7 | import fr.umlv.java.wallj.block.GarbageBlock; |
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 GarbageDisplayController extends DisplayController { | |||
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.paintCircle(new Color(102, 51, 0), garbage.getPos(),TileVec2.TILE_DIM); |
27 | return Collections.emptyList(); | ||
23 | } | 28 | } |
24 | 29 | ||
25 | } | 30 | } |
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 680bca8..4272ae7 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 @@ | |||