aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/docs/class.puml33
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/Board.java41
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/TileVec2.java81
-rw-r--r--src/main/java/fr/umlv/java/wallj/model/BlockType.java14
-rw-r--r--src/main/java/fr/umlv/java/wallj/utils/TileVec2.java5
5 files changed, 147 insertions, 27 deletions
diff --git a/src/docs/class.puml b/src/docs/class.puml
index f4766db..7a00135 100644
--- a/src/docs/class.puml
+++ b/src/docs/class.puml
@@ -6,15 +6,6 @@ package utils {
6 class PathFinder { 6 class PathFinder {
7 static List<Vec2> findPath(Board, TileVec2, TileVec2) 7 static List<Vec2> findPath(Board, TileVec2, TileVec2)
8 } 8 }
9
10 class TileVec2 {
11 static final int TILE_DIM
12
13 Vec2
14 TileVec2(Vec2)
15 Vec2 toPixelPos()
16 static TileVec2 fromPixelPos(Vec2)
17 }
18} 9}
19 10
20package viewer { 11package viewer {
@@ -76,7 +67,9 @@ package event {
76 67
77package board { 68package board {
78 class Board { 69 class Board {
79 BlockType[][] 70 Board(width, height)
71 BlockType getBlockTypeAt(TileVec2)
72 BlockType setBlockTypeAt(TileVec2, BlockType)
80 } 73 }
81 74
82 class BoardParser { 75 class BoardParser {
@@ -91,15 +84,25 @@ package board {
91 static Board worldToBoard(List<Block>) 84 static Board worldToBoard(List<Block>)
92 static List<Block> boardToWorld(Board) 85 static List<Block> boardToWorld(Board)
93 } 86 }
87
88 class TileVec2 {
89 static final int TILE_DIM
90 static TileVec2 fromVec2(Vec2)
91
92 Vec2
93 TileVec2(col, row)
94 Vec2 toPixelPos()
95 }
94} 96}
95 97
96package model { 98package model {
97 enum BlockType { 99 enum BlockType {
98 Wall 100 FREE
99 Trash 101 WALL
100 Garbage 102 TRASH
101 Robot 103 GARBAGE
102 Bomb 104 ROBOT
105 BOMB
103 } 106 }
104 107
105 class BlockFactory { 108 class BlockFactory {
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 d20517a..ebe1a7e 100644
--- a/src/main/java/fr/umlv/java/wallj/board/Board.java
+++ b/src/main/java/fr/umlv/java/wallj/board/Board.java
@@ -1,5 +1,42 @@
1package fr.umlv.java.wallj.board; 1package fr.umlv.java.wallj.board;
2 2
3public class Board { 3import fr.umlv.java.wallj.model.BlockType;
4 //TODO 4
5/**
6 * A mutable BlockType matrix.
7 */
8public final class Board {
9
10 private final BlockType[][] map;
11
12 public Board(int width, int height) {
13 map = new BlockType[width][height];
14 }
15
16 /**
17 * @param pos the tile position vector
18 * @return the element at the given position
19 */
20 public BlockType getBlockTypeAt(TileVec2 pos) {
21 return map[pos.getCol()][pos.getRow()];
22 }
23
24 /**
25 * @param pos the tile position vector
26 * @param type the BlockType to set
27 * @return the overwritten element
28 */
29 public BlockType setBlockTypeAt(TileVec2 pos, BlockType type) {
30 BlockType old = map[pos.getCol()][pos.getRow()];
31 map[pos.getCol()][pos.getRow()] = type;
32 return old;
33 }
34
35 /**
36 * @return the dimension of the Board
37 */
38 public TileVec2 getDim() {
39 return TileVec2.of(map.length, map.length > 0 ? map[0].length : 0);
40 }
41
5} 42}
diff --git a/src/main/java/fr/umlv/java/wallj/board/TileVec2.java b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java
new file mode 100644
index 0000000..ac28b6d
--- /dev/null
+++ b/src/main/java/fr/umlv/java/wallj/board/TileVec2.java
@@ -0,0 +1,81 @@
1package fr.umlv.java.wallj.board;
2
3import org.jbox2d.common.Vec2;
4
5import java.util.Objects;
6
7/**
8 * A typed immutable tile coordinate vector containing the coordinates of a Tile in a Board.
9 */
10public final class TileVec2 {
11
12 private static final int TILE_DIM = 20;
13
14 /**
15 * @param row the row
16 * @param col the column
17 * @return a corresponding tile vector
18 */
19 public static TileVec2 of(int row, int col) {
20 return new TileVec2(row, col);
21 }
22
23 /**
24 * @param v a JBox2D Vec2 vector
25 * @return the coordinates of the tile containing the given point
26 */
27 public static TileVec2 of(Vec2 v) {
28 return new TileVec2((int) (v.x / TILE_DIM), (int) (v.y / TILE_DIM));
29 }
30
31 private final int row, col;
32
33 private TileVec2(int row, int col) {
34 this.row = row;
35 this.col = col;
36 }
37
38 /**
39 * @return the row
40 */
41 public int getRow() {
42 return row;
43 }
44
45 /**
46 * @return the column
47 */
48 public int getCol() {
49 return col;
50 }
51
52 /**
53 * @return the corresponding JBox2D coordinates of the top-left corner of the tile
54 */
55 public Vec2 toVec2() {
56 return new Vec2(row * TILE_DIM, col * TILE_DIM);
57 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) return true;
62 if (!(o instanceof TileVec2)) return false;
63 TileVec2 tileVec2 = (TileVec2) o;
64 return row == tileVec2.row &&
65 col == tileVec2.col;
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(row, col);
71 }
72
73 @Override
74 public String toString() {
75 return "TileVec2{" +
76 "row=" + row +
77 ", col=" + col +
78 '}';
79 }
80
81}
diff --git a/src/main/java/fr/umlv/java/wallj/model/BlockType.java b/src/main/java/fr/umlv/java/wallj/model/BlockType.java
index 0cd9eda..64ef602 100644
--- a/src/main/java/fr/umlv/java/wallj/model/BlockType.java
+++ b/src/main/java/fr/umlv/java/wallj/model/BlockType.java
@@ -1,9 +1,13 @@
1package fr.umlv.java.wallj.model; 1package fr.umlv.java.wallj.model;
2 2
3/**
4 * Enumeration of the types of blocks handled in the game.
5 */
3public enum BlockType { 6public enum BlockType {
4 Wall, 7 FREE,
5 Trash, 8 wALL,
6 Garbage, 9 TRASH,
7 Robot, 10 GARBAGE,
8 Bomb 11 ROBOT,
12 BOMB
9} 13}
diff --git a/src/main/java/fr/umlv/java/wallj/utils/TileVec2.java b/src/main/java/fr/umlv/java/wallj/utils/TileVec2.java
deleted file mode 100644
index e88558a..0000000
--- a/src/main/java/fr/umlv/java/wallj/utils/TileVec2.java
+++ /dev/null
@@ -1,5 +0,0 @@
1package fr.umlv.java.wallj.utils;
2
3public class TileVec2 {
4 //TODO
5}