aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/fr/umlv
diff options
context:
space:
mode:
authorAdam NAILI2018-01-11 20:07:28 +0100
committerAdam NAILI2018-01-11 20:07:28 +0100
commit1347f30afbed7ee9c149f77534f5e75fbe819b98 (patch)
tree92d68934e527a2a9b7faa91e048d0ccd0bd65da3 /src/main/java/fr/umlv
parente5f4426230fc485feac96fd5db6151faad24591d (diff)
downloadwallj-1347f30afbed7ee9c149f77534f5e75fbe819b98.tar.gz
Implementing BoardConverter and test failed
Diffstat (limited to 'src/main/java/fr/umlv')
-rw-r--r--src/main/java/fr/umlv/java/wallj/board/BoardConverter.java40
1 files changed, 39 insertions, 1 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 9f5736a..0f8359b 100644
--- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
+++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
@@ -1,5 +1,43 @@
1package fr.umlv.java.wallj.board; 1package fr.umlv.java.wallj.board;
2 2
3public class BoardConverter { 3import fr.umlv.java.wallj.model.*;
4
5import java.util.ArrayList;
6import java.util.List;
7
8/**
9 * @author Adam NAILI
10 */
11public final class BoardConverter {
4 //TODO 12 //TODO
13 private BoardConverter() {
14 }
15
16 public static Board worldToBoard(List<Block> blocks) {
17 int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1;
18 int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1;
19
20 Board.Builder builder = new Board.Builder(width, height);
21 for (Block block : blocks) {
22 builder.setBlockTypeAt(block.getTile(), block.getType());
23 }
24 return builder.build();
25 }
26
27 public static List<Block> boardToWorld(Board board) {
28 ArrayList<Block> blocks = new ArrayList<>();
29 int nbRow = board.getDim().getRow();
30 int nbCol = board.getDim().getCol();
31 for (int i = 0; i < nbRow; i++) {
32 for (int j = 0; i < nbCol; j++) {
33 Block block;
34 TileVec2 location = TileVec2.of(i, j);
35 block = BlockFactory.build(board.getBlockTypeAt(location), location);
36 if (block != null) {
37 blocks.add(block);
38 }
39 }
40 }
41 return blocks;
42 }
5} 43}