aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/Lists.java38
-rw-r--r--src/ch/epfl/xblast/server/Block.java4
-rw-r--r--src/ch/epfl/xblast/server/Board.java123
3 files changed, 163 insertions, 2 deletions
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java
new file mode 100644
index 0000000..096ceba
--- /dev/null
+++ b/src/ch/epfl/xblast/Lists.java
@@ -0,0 +1,38 @@
1package ch.epfl.xblast;
2
3import java.util.List;
4import java.util.ArrayList;
5import java.util.Collections;
6
7/**
8 * @author Pacien TRAN-GIRARD (261948)
9 * @author Timothée FLOURE (257420)
10 */
11public final class Lists {
12 /**
13 * Return a sysmetric version of the list.
14 *
15 * @param l the input list
16 * @throws IllegalArgumentException if the given list is empty
17 * @return mirroredList the mirrored ilist
18 */
19 public static <T> List<T> mirrored(List<T> l) {
20 if (l.size() == 0) {
21 throw new IllegalArgumentException();
22 }
23
24 List<T> mirroredList = new ArrayList<T>();
25 List<T> rightSide = new ArrayList<T>();
26
27 for (int i=0;i < l.size()-1;i++) {
28 rightSide.add(l.get(i));
29 }
30
31 Collections.reverse(rightSide);
32
33 mirroredList.addAll(l);
34 mirroredList.addAll(rightSide);
35
36 return mirroredList;
37 }
38}
diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java
index 75925a3..8268f33 100644
--- a/src/ch/epfl/xblast/server/Block.java
+++ b/src/ch/epfl/xblast/server/Block.java
@@ -45,7 +45,7 @@ public enum Block {
45 * 45 *
46 * @returns T(this block cast a shadow) 46 * @returns T(this block cast a shadow)
47 */ 47 */
48 public boolean castsSahdow() { 48 public boolean castsShadow() {
49 return this == INDESTRUCTIBLE_WALL || this == DESTRUCTILE_WALL || this == CRUMBLING_WALL; 49 return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL;
50 } 50 }
51} 51}
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java
new file mode 100644
index 0000000..c8d3e01
--- /dev/null
+++ b/src/ch/epfl/xblast/server/Board.java
@@ -0,0 +1,123 @@
1package ch.epfl.xblast.server;
2
3import java.util.List;
4import java.util.ArrayList;
5import ch.epfl.cs108.Sq;
6import ch.epfl.xblast.Lists;
7
8/**
9 * @author Pacien TRAN-GIRARD (261948)
10 * @author Timothée FLOURE (257420)
11 */
12
13public final class Board {
14 /**
15 * List containing all the blocks of the board.
16 */
17 private List<Sq<Block>> blocks;
18
19 /**
20 * Instanciates a new Board with the given sequence of blocks.
21 *
22 * @throws IllegalArgumentEception if the blocks is not composed of 195 elements
23 * @param blocks sequence conataining all the blocks of the Boards
24 */
25 public Board (List<Sq<Block>> blocks) {
26 if (blocks.size() != 195) {
27 throw new IllegalArgumentException();
28 }
29 this.blocks = blocks;
30 }
31
32 /**
33 * Build a new Board with the given Matrix.
34 *
35 * @param rows list containing all the rows
36 * @throws IllegalArgumentException if rows is not 13*15
37 * @return a new Board built with given rows
38 */
39 public static Board ofRows(List<List<Block>> rows) {
40 if (rows.size() != 13) {
41 throw new IllegalArgumentException();
42 }
43
44 List<Sq<Block>> blocksSequence = new ArrayList<>();
45
46 for (int i = 0; i < rows.size(); i++) {
47
48 if (rows.get(i).size() != 15) {
49 throw new IllegalArgumentException();
50 }
51
52 for (int j = 0; j < rows.get(i).size(); j++) {
53 blocksSequence.add(Sq.constant(rows.get(i).get(j)));
54 }
55 }
56
57 return new Board(blocksSequence);
58 }
59
60 /**
61 * Build a walled board filled with the given inner rows
62 *
63 * @param innerBlocks lists of the internal rows
64 * @throws IllegalArgumentException if innerbLocks is not 11*13
65 * @return a new walled board filled with the given rows
66 */
67 public static Board ofInnerBlocksWalled(List<List<Block>> innerBlocks) {
68 if (innerBlocks.size() != 11) {
69 throw new IllegalArgumentException();
70 }
71
72 List<List<Block>> rowsList = new ArrayList<>();
73 List<Block> wallLine = new ArrayList<>();
74
75 for (int i = 0; i < 15;i++) {
76 wallLine.add(Block.INDESTRUCTIBLE_WALL);
77 }
78
79 for (int i = 0; i < innerBlocks.size(); i++) {
80 if (innerBlocks.get(i).size() != 13) {
81 throw new IllegalArgumentException();
82 }
83
84 List<Block> row = innerBlocks.get(i);
85 row.add(0,Block.INDESTRUCTIBLE_WALL);
86 row.add(Block.INDESTRUCTIBLE_WALL);
87
88 rowsList.add(row);
89 }
90
91 rowsList.add(0,wallLine);
92 rowsList.add(wallLine);
93
94 return ofRows(rowsList);
95 }
96
97 /**
98 * Build a symetric walled board from the NWB quadrant.
99 *
100 * @param quadrantNWBlocks the NW quadrant of the board (inner blocks only!)
101 * @throws IllegalArgumentException if quadrantNWBlocks is not 6*7
102 * @return a new walled board simmetricaly filled with the given NW quadrant
103 */
104 public static Board ofQuadrantNWBlocksWalled(List<List<Block>> quadrantNWBlocks) {
105 if (quadrantNWBlocks.size() != 6) {
106 throw new IllegalArgumentException();
107 }
108
109 List<List<Block>> rowsList = new ArrayList<>();
110
111 List<List<Block>> halfInnerBoard = Lists.<List<Block>>mirrored(quadrantNWBlocks);
112
113 for (int i = 0; i < halfInnerBoard.size(); i++) {
114 if (halfInnerBoard.get(i).size() != 7) {
115 throw new IllegalArgumentException();
116 }
117
118 rowsList.add(Lists.<Block>mirrored(halfInnerBoard.get(i)));
119 }
120
121 return ofInnerBlocksWalled(rowsList);
122 }
123}