aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv
diff options
context:
space:
mode:
authorpacien2018-01-14 23:11:42 +0100
committerpacien2018-01-14 23:11:42 +0100
commit12c9d15bc951dbc80832104f68e5c6e140bdb770 (patch)
treeaf3c51dd10ff06564eb5b29eba5e1f48ef8e5eea /src/main/java/fr/umlv
parent0a73db0e47a93dcf70be2ed75cd64e1762ae316c (diff)
parentc0dbbdc990a68a99b2d913bba9698d7e0894e924 (diff)
downloadwallj-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')
-rw-r--r--src/main/java/fr/umlv/java/wallj/Main.java18
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/GraphicsContext.java10
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BombDisplayController.java14
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/BombPhysicsController.java3
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/GarbageDisplayController.java9
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/RobotDisplayController.java9
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/RobotPhysicsController.java3
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/TrashDisplayController.java9
-rw-r--r--src/main/java/fr/umlv/java/wallj/controller/WallDisplayController.java2
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
3import fr.umlv.java.wallj.board.Board; 3import fr.umlv.java.wallj.board.Board;
4import fr.umlv.java.wallj.board.BoardParser; 4import fr.umlv.java.wallj.board.BoardParser;
5import fr.umlv.java.wallj.board.BoardValidator;
5import fr.umlv.java.wallj.viewer.Viewer; 6import fr.umlv.java.wallj.viewer.Viewer;
6import fr.umlv.zen5.Application; 7import 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 @@
1package fr.umlv.java.wallj.context; 1package fr.umlv.java.wallj.context;
2 2
3import fr.umlv.java.wallj.board.TileVec2;
3import fr.umlv.zen5.ScreenInfo; 4import fr.umlv.zen5.ScreenInfo;
4import org.jbox2d.common.Vec2; 5import 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 @@
1package fr.umlv.java.wallj.controller; 1package fr.umlv.java.wallj.controller;
2 2
3import fr.umlv.java.wallj.board.TileVec2;
3import fr.umlv.java.wallj.context.Context; 4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.context.GraphicsContext;
4import fr.umlv.java.wallj.event.Event; 6import fr.umlv.java.wallj.event.Event;
5import fr.umlv.java.wallj.block.BombBlock; 7import fr.umlv.java.wallj.block.BombBlock;
8import org.jbox2d.common.Vec2;
6 9
10import java.awt.*;
11import java.util.Collections;
7import java.util.List; 12import java.util.List;
8import java.util.Objects; 13import 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;
4import fr.umlv.java.wallj.event.Event; 4import fr.umlv.java.wallj.event.Event;
5import fr.umlv.java.wallj.block.BombBlock; 5import fr.umlv.java.wallj.block.BombBlock;
6 6
7import java.util.Collections;
7import java.util.List; 8import java.util.List;
8import java.util.Objects; 9import 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 @@
1package fr.umlv.java.wallj.controller; 1package fr.umlv.java.wallj.controller;
2 2
3import fr.umlv.java.wallj.board.TileVec2;
3import fr.umlv.java.wallj.context.Context; 4import fr.umlv.java.wallj.context.Context;
5import fr.umlv.java.wallj.context.GraphicsContext;
4import fr.umlv.java.wallj.event.Event; 6import fr.umlv.java.wallj.event.Event;
5import fr.umlv.java.wallj.block.GarbageBlock; 7import fr.umlv.java.wallj.block.GarbageBlock;
6 8
9import java.awt.*;
10import java.util.Collections;
7import java.util.List; 11import java.util.List;
8import java.util.Objects; 12import 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 @@