diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index 4d2e743..5e03671 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java | |||
@@ -32,15 +32,12 @@ public final class Board { | |||
32 | * @throws IllegalArgumentException if the matrix does not comply with the given sizes. | 32 | * @throws IllegalArgumentException if the matrix does not comply with the given sizes. |
33 | */ | 33 | */ |
34 | private static void checkBlockMatrix(List<List<Block>> matrix, int rows, int columns) { | 34 | private static void checkBlockMatrix(List<List<Block>> matrix, int rows, int columns) { |
35 | if (matrix.size() != rows) { | 35 | if (matrix == null || matrix.size() != rows) |
36 | throw new IllegalArgumentException(); | 36 | throw new IllegalArgumentException(); |
37 | } else { | 37 | |
38 | for (int i = 0; i < rows; i++) { | 38 | for (int i = 0; i < rows; i++) |
39 | if (matrix.get(i).size() != columns) { | 39 | if (matrix.get(i).size() != columns) |
40 | throw new IllegalArgumentException(); | 40 | throw new IllegalArgumentException(); |
41 | } | ||
42 | } | ||
43 | } | ||
44 | } | 41 | } |
45 | 42 | ||
46 | /** | 43 | /** |
@@ -55,9 +52,9 @@ public final class Board { | |||
55 | * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements | 52 | * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements |
56 | */ | 53 | */ |
57 | public Board(List<Sq<Block>> blocks) { | 54 | public Board(List<Sq<Block>> blocks) { |
58 | if (blocks.size() != BLOCKS_LIST_SIZE) { | 55 | if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE) |
59 | throw new IllegalArgumentException(); | 56 | throw new IllegalArgumentException(); |
60 | } | 57 | |
61 | this.blocks = blocks; | 58 | this.blocks = blocks; |
62 | } | 59 | } |
63 | 60 | ||
@@ -72,11 +69,9 @@ public final class Board { | |||
72 | checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); | 69 | checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS); |
73 | List<Sq<Block>> blocksSequence = new ArrayList<>(); | 70 | List<Sq<Block>> blocksSequence = new ArrayList<>(); |
74 | 71 | ||
75 | for (int i = 0; i < rows.size(); i++) { | 72 | for (List<Block> row : rows) |
76 | for (int j = 0; j < rows.get(i).size(); j++) { | 73 | for (Block aRow : row) |
77 | blocksSequence.add(Sq.constant(rows.get(i).get(j))); | 74 | blocksSequence.add(Sq.constant(aRow)); |
78 | } | ||
79 | } | ||
80 | 75 | ||
81 | return new Board(blocksSequence); | 76 | return new Board(blocksSequence); |
82 | } | 77 | } |
@@ -93,12 +88,10 @@ public final class Board { | |||
93 | List<List<Block>> rowsList = new ArrayList<>(); | 88 | List<List<Block>> rowsList = new ArrayList<>(); |
94 | List<Block> wallLine = new ArrayList<>(); | 89 | List<Block> wallLine = new ArrayList<>(); |
95 | 90 | ||
96 | for (int i = 0; i < BOARD_COLUMNS; i++) { | 91 | for (int i = 0; i < BOARD_COLUMNS; i++) |
97 | wallLine.add(Block.INDESTRUCTIBLE_WALL); | 92 | wallLine.add(Block.INDESTRUCTIBLE_WALL); |
98 | } | ||
99 | 93 | ||
100 | for (int i = 0; i < innerBlocks.size(); i++) { | 94 | for (List<Block> row : innerBlocks) { |
101 | List<Block> row = innerBlocks.get(i); | ||
102 | row.add(0, Block.INDESTRUCTIBLE_WALL); | 95 | row.add(0, Block.INDESTRUCTIBLE_WALL); |
103 | row.add(Block.INDESTRUCTIBLE_WALL); | 96 | row.add(Block.INDESTRUCTIBLE_WALL); |
104 | 97 | ||
@@ -123,9 +116,9 @@ public final class Board { | |||
123 | List<List<Block>> rowsList = new ArrayList<>(); | 116 | List<List<Block>> rowsList = new ArrayList<>(); |
124 | List<List<Block>> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); | 117 | List<List<Block>> halfInnerBoard = Lists.mirrored(quadrantNWBlocks); |
125 | 118 | ||
126 | for (int i = 0; i < halfInnerBoard.size(); i++) { | 119 | for (List<Block> aHalfInnerBoard : halfInnerBoard) |
127 | rowsList.add(Lists.mirrored(halfInnerBoard.get(i))); | 120 | rowsList.add(Lists.mirrored(aHalfInnerBoard)); |
128 | } | 121 | |
129 | return ofInnerBlocksWalled(rowsList); | 122 | return ofInnerBlocksWalled(rowsList); |
130 | } | 123 | } |
131 | 124 | ||