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.java8
-rw-r--r--src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java29
2 files changed, 31 insertions, 6 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 0f8359b..6231875 100644
--- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
+++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java
@@ -14,8 +14,8 @@ public final class BoardConverter {
14 } 14 }
15 15
16 public static Board worldToBoard(List<Block> blocks) { 16 public static Board worldToBoard(List<Block> blocks) {
17 int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; 17 int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1;
18 int height = 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;
19 19
20 Board.Builder builder = new Board.Builder(width, height); 20 Board.Builder builder = new Board.Builder(width, height);
21 for (Block block : blocks) { 21 for (Block block : blocks) {
@@ -29,9 +29,9 @@ public final class BoardConverter {
29 int nbRow = board.getDim().getRow(); 29 int nbRow = board.getDim().getRow();
30 int nbCol = board.getDim().getCol(); 30 int nbCol = board.getDim().getCol();
31 for (int i = 0; i < nbRow; i++) { 31 for (int i = 0; i < nbRow; i++) {
32 for (int j = 0; i < nbCol; j++) { 32 for (int j = 0; j < nbCol; j++) {
33 Block block; 33 Block block;
34 TileVec2 location = TileVec2.of(i, j); 34 TileVec2 location = TileVec2.of(j,i);
35 block = BlockFactory.build(board.getBlockTypeAt(location), location); 35 block = BlockFactory.build(board.getBlockTypeAt(location), location);
36 if (block != null) { 36 if (block != null) {
37 blocks.add(block); 37 blocks.add(block);
diff --git a/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java b/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java
index 9574adf..ad96ea1 100644
--- a/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java
+++ b/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java
@@ -29,7 +29,6 @@ final class BoardConverterTest {
29 builder.setBlockTypeAt(t2,BlockType.GARBAGE); 29 builder.setBlockTypeAt(t2,BlockType.GARBAGE);
30 builder.setBlockTypeAt(t3,BlockType.ROBOT); 30 builder.setBlockTypeAt(t3,BlockType.ROBOT);
31 builder.setBlockTypeAt(t4,BlockType.TRASH); 31 builder.setBlockTypeAt(t4,BlockType.TRASH);
32
33 Board certifiedBoard = builder.build(); 32 Board certifiedBoard = builder.build();
34 33
35 blocks.add(BlockFactory.build(BlockType.WALL,t0)); 34 blocks.add(BlockFactory.build(BlockType.WALL,t0));
@@ -37,12 +36,38 @@ final class BoardConverterTest {
37 blocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); 36 blocks.add(BlockFactory.build(BlockType.GARBAGE,t2));
38 blocks.add(BlockFactory.build(BlockType.ROBOT,t3)); 37 blocks.add(BlockFactory.build(BlockType.ROBOT,t3));
39 blocks.add(BlockFactory.build(BlockType.TRASH,t4)); 38 blocks.add(BlockFactory.build(BlockType.TRASH,t4));
40
41 Board board = BoardConverter.worldToBoard(blocks); 39 Board board = BoardConverter.worldToBoard(blocks);
42 40
43 Assertions.assertEquals(certifiedBoard,board); 41 Assertions.assertEquals(certifiedBoard,board);
42 }
43
44 @Test
45 void testBoardToWorld(){
46 Board.Builder builder = new Board.Builder(5,1);
47 TileVec2 t0 = TileVec2.of(0,0);
48 TileVec2 t1 = TileVec2.of(1,0);
49 TileVec2 t2 = TileVec2.of(2,0);
50 TileVec2 t3 = TileVec2.of(3,0);
51 TileVec2 t4 = TileVec2.of(4,0);
52
53 builder.setBlockTypeAt(t0,BlockType.WALL);
54 builder.setBlockTypeAt(t1,BlockType.BOMB);
55 builder.setBlockTypeAt(t2,BlockType.GARBAGE);
56 builder.setBlockTypeAt(t3,BlockType.ROBOT);
57 builder.setBlockTypeAt(t4,BlockType.TRASH);
58 Board board = builder.build();
59
60 List<Block> certifiedBlocks = new LinkedList<>();
44 61
62 certifiedBlocks.add(BlockFactory.build(BlockType.WALL,t0));
63 certifiedBlocks.add(BlockFactory.build(BlockType.BOMB,t1));
64 certifiedBlocks.add(BlockFactory.build(BlockType.GARBAGE,t2));
65 certifiedBlocks.add(BlockFactory.build(BlockType.ROBOT,t3));
66 certifiedBlocks.add(BlockFactory.build(BlockType.TRASH,t4));
67
68 List<Block> blocks = BoardConverter.boardToWorld(board);
45 } 69 }
46 70
71
47} 72}
48 73