aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam NAILI2018-02-04 23:34:13 +0100
committerAdam NAILI2018-02-04 23:34:13 +0100
commit8554edc96eb2da6510fa4159873b940f1202fae3 (patch)
tree83d7ba5b4f60bf6e447a3293d094545bc197d29b
parent2280104d4f596d6eec97cb341709b418c312f685 (diff)
downloadwallj-8554edc96eb2da6510fa4159873b940f1202fae3.tar.gz
Rearranging the code
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/BlockFactory.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/block/SolidDef.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/Board.java64
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/BoardParser.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/BoardValidator.java74
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/Matrix.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/PathFinder.java61
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/TileVec2.java13
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Game.java2
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Stage.java16
-rw-r--r--src/main/java/fr/umlv/java/wallj/context/Updateables.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/event/Events.java8
-rw-r--r--src/main/java/fr/umlv/java/wallj/viewer/Main.java8
13 files changed, 142 insertions, 144 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java b/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
index 6911c88..411696d 100644
--- a/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
+++ b/src/main/java/fr/umlv/java/wallj/block/BlockFactory.java
@@ -9,6 +9,10 @@ import org.jbox2d.common.Vec2;
9 * @author Pacien TRAN-GIRARD 9 * @author Pacien TRAN-GIRARD
10 */ 10 */
11public final class BlockFactory { 11public final class BlockFactory {
12 private BlockFactory() {
13 // static class
14 }
15
12 private static Block forType(BlockType t, Vec2 pos) { 16 private static Block forType(BlockType t, Vec2 pos) {
13 switch (t) { 17 switch (t) {
14 case WALL: 18 case WALL:
@@ -35,8 +39,4 @@ public final class BlockFactory {
35 public static Block build(BlockType type, TileVec2 pos) { 39 public static Block build(BlockType type, TileVec2 pos) {
36 return forType(type, pos.toVec2()); 40 return forType(type, pos.toVec2());
37 } 41 }
38
39 private BlockFactory() {
40 // static class
41 }
42} 42}
diff --git a/src/main/java/fr/umlv/java/wallj/block/SolidDef.java b/src/main/java/fr/umlv/java/wallj/block/SolidDef.java
index 6fb7dc3..25ff022 100644
--- a/src/main/java/fr/umlv/java/wallj/block/SolidDef.java
+++ b/src/main/java/fr/umlv/java/wallj/block/SolidDef.java
@@ -13,6 +13,10 @@ import org.jbox2d.dynamics.FixtureDef;
13 * @author Pacien TRAN-GIRARD 13 * @author Pacien TRAN-GIRARD
14 */ 14 */
15public final class SolidDef { 15public final class SolidDef {
16 private SolidDef() {
17 // static class
18 }
19
16 /** 20 /**
17 * @param bodyType type of body 21 * @param bodyType type of body
18 * @param pos initial position of the body 22 * @param pos initial position of the body
@@ -53,8 +57,4 @@ public final class SolidDef {
53 shape.m_radius = TileVec2.TILE_DIM / 2; 57 shape.m_radius = TileVec2.TILE_DIM / 2;
54 return shape; 58 return shape;
55 } 59 }
56
57 private SolidDef() {
58 // static class
59 }
60} 60}
diff --git a/src/main/java/fr/umlv/java/wallj/board/Board.java b/src/main/java/fr/umlv/java/wallj/board/Board.java
index 2e67c53..077dd26 100644
--- a/src/main/java/fr/umlv/java/wallj/board/Board.java
+++ b/src/main/java/fr/umlv/java/wallj/board/Board.java
@@ -15,38 +15,6 @@ import java.util.stream.Stream;
15 */ 15 */
16public final class Board { 16public final class Board {
17 17
18 /**
19 * Board Builder
20 */
21 public static final class Builder {
22 private final BlockType[][] map;
23
24 /**
25 * @param width width in tiles
26 * @param height height in tiles
27 */
28 public Builder(int width, int height) {
29 map = new BlockType[height][width];
30 }
31
32 /**
33 * @param pos the tile position vector
34 * @param type the BlockType to set
35 * @return the Builder
36 */
37 public Builder setBlockTypeAt(TileVec2 pos, BlockType type) {
38 map[pos.getRow()][pos.getCol()] = type;
39 return this;
40 }
41
42 /**
43 * @return the immutable Board
44 */
45 public Board build() {
46 return new Board(map);
47 }
48 }
49
50 private final BlockType[][] map; 18 private final BlockType[][] map;
51 19
52 private Board(BlockType[][] map) { 20 private Board(BlockType[][] map) {
@@ -103,4 +71,36 @@ public final class Board {
103 return Arrays.hashCode(map); 71 return Arrays.hashCode(map);
104 } 72 }
105 73
74 /**
75 * Board Builder
76 */
77 public static final class Builder {
78 private final BlockType[][] map;
79
80 /**
81 * @param width width in tiles
82 * @param height height in tiles
83 */
84 public Builder(int width, int height) {
85 map = new BlockType[height][width];
86 }
87
88 /**
89 * @param pos the tile position vector
90 * @param type the BlockType to set
91 * @return the Builder
92 */
93 public Builder setBlockTypeAt(TileVec2 pos, BlockType type) {
94 map[pos.getRow()][pos.getCol()] = type;
95 return this;
96 }
97
98 /**
99 * @return the immutable Board
100 */
101 public Board build() {
102 return new Board(map);
103 }
104 }
105
106} 106}
diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java
index 90fd9c2..71bdc51 100644
--- a/src/main/java/fr/umlv/java/wallj/board/BoardParser.java
+++ b/src/main/java/fr/umlv/java/wallj/board/BoardParser.java
@@ -15,6 +15,10 @@ import java.util.stream.Collectors;
15 * @author Pacien TRAN-GIRARD 15 * @author Pacien TRAN-GIRARD
16 */ 16 */
17public final class BoardParser { 17public final class BoardParser {
18 private BoardParser() {
19 // static class
20 }
21
18 private static Board buildBoard(List<List<BlockType>> map) { 22 private static Board buildBoard(List<List<BlockType>> map) {
19 if (!Matrix.isShapeValid(map)) throw new IllegalArgumentException("Board must be rectangular."); 23 if (!Matrix.isShapeValid(map)) throw new IllegalArgumentException("Board must be rectangular.");
20 24
@@ -60,8 +64,4 @@ public final class BoardParser {
60 .map(BoardParser::parseLine) 64 .map(BoardParser::parseLine)
61 .collect(Collectors.toList())); 65 .collect(Collectors.toList()));
62 } 66 }
63
64 private BoardParser() {
65 // static class
66 }
67} 67}
diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java b/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java
index 011ca8b..d7d3583 100644
--- a/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java
+++ b/src/main/java/fr/umlv/java/wallj/board/BoardValidator.java
@@ -13,6 +13,39 @@ import java.util.stream.IntStream;
13 */ 13 */
14public class BoardValidator { 14public class BoardValidator {
15 15
16 private final Board board;
17 private final ValidationException errors = new ValidationException();
18
19 /**
20 * @param board the board to validate
21 */
22 public BoardValidator(Board board) {
23 this.board = board;
24 }
25
26 /**
27 * Tests the board against a given validator, using the supplied error message if the validation fails.
28 *
29 * @param validator a validity test
30 * @param msg a failure message
31 * @return the board validator
32 */
33 public BoardValidator validate(Predicate<Board> validator, String msg) {
34 if (!validator.test(board)) errors.addSuppressed(new ValidationException(msg));
35 return this;
36 }
37
38 /**
39 * @return the validated board
40 * @throws ValidationException in case of failure
41 */
42 public Board get() throws ValidationException {
43 if (errors.getSuppressed().length > 0)
44 throw errors;
45 else
46 return board;
47 }
48
16 /** 49 /**
17 * A validation exception, witness of validation error(s). 50 * A validation exception, witness of validation error(s).
18 */ 51 */
@@ -33,6 +66,10 @@ public class BoardValidator {
33