aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/BoardConverter.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
index 6231875..c4d47cc 100644
--- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
+++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
@@ -6,13 +6,17 @@ import java.util.ArrayList;
6import java.util.List; 6import java.util.List;
7 7
8/** 8/**
9 * Operations of conversion on Board and List of blocks
9 * @author Adam NAILI 10 * @author Adam NAILI
10 */ 11 */
11public final class BoardConverter { 12public final class BoardConverter {
12 //TODO
13 private BoardConverter() { 13 private BoardConverter() {
14 } 14 }
15 15
16 /**
17 * @param blocks the list of blocks to convert in a board
18 * @return the converted board
19 */
16 public static Board worldToBoard(List<Block> blocks) { 20 public static Board worldToBoard(List<Block> blocks) {
17 int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1; 21 int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1;
18 int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; 22 int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1;
@@ -24,6 +28,10 @@ public final class BoardConverter {
24 return builder.build(); 28 return builder.build();
25 } 29 }
26 30
31 /**
32 * @param board the board to convert into a list of blocks
33 * @return the list of blocks converted
34 */
27 public static List<Block> boardToWorld(Board board) { 35 public static List<Block> boardToWorld(Board board) {
28 ArrayList<Block> blocks = new ArrayList<>(); 36 ArrayList<Block> blocks = new ArrayList<>();
29 int nbRow = board.getDim().getRow(); 37 int nbRow = board.getDim().getRow();
@@ -31,7 +39,7 @@ public final class BoardConverter {
31 for (int i = 0; i < nbRow; i++) { 39 for (int i = 0; i < nbRow; i++) {
32 for (int j = 0; j < nbCol; j++) { 40 for (int j = 0; j < nbCol; j++) {
33 Block block; 41 Block block;
34 TileVec2 location = TileVec2.of(j,i); 42 TileVec2 location = TileVec2.of(j, i);
35 block = BlockFactory.build(board.getBlockTypeAt(location), location); 43 block = BlockFactory.build(board.getBlockTypeAt(location), location);
36 if (block != null) { 44 if (block != null) {
37 blocks.add(block); 45 blocks.add(block);