diff options
-rw-r--r-- | src/ch/epfl/xblast/Lists.java | 38 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Block.java | 4 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 123 | ||||
-rw-r--r-- | test/ch/epfl/xblast/ListsTest.java | 32 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck02.java | 60 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BlockTest.java | 35 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BoardTest.java | 137 |
7 files changed, 427 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 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.ArrayList; | ||
5 | import java.util.Collections; | ||
6 | |||
7 | /** | ||
8 | * @author Pacien TRAN-GIRARD (261948) | ||
9 | * @author Timothée FLOURE (257420) | ||
10 | */ | ||
11 | public 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 @@ | |||
1 | package ch.epfl.xblast.server; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.ArrayList; | ||
5 | import ch.epfl.cs108.Sq; | ||
6 | import ch.epfl.xblast.Lists; | ||
7 | |||
8 | /** | ||
9 | * @author Pacien TRAN-GIRARD (261948) | ||
10 | * @author Timothée FLOURE (257420) | ||
11 | */ | ||
12 | |||
13 | public 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 | } | ||
diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java new file mode 100644 index 0000000..6a98b3f --- /dev/null +++ b/test/ch/epfl/xblast/ListsTest.java | |||
@@ -0,0 +1,32 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.Arrays; | ||
5 | import static org.junit.Assert.*; | ||
6 | import org.junit.Test; | ||
7 | |||
8 | /** | ||
9 | * @author Pacien TRAN-GIRARD (261948) | ||
10 | * @author Timothée FLOURE (257420) | ||
11 | */ | ||
12 | public class ListsTest { | ||
13 | @Test(expected=IllegalArgumentException.class) | ||
14 | public void isEmptyListThrowingException() { | ||
15 | List<Integer> sampleList = Arrays.asList(); | ||
16 | Lists.<Integer>mirrored(sampleList); | ||
17 | } | ||
18 | |||
19 | @Test(expected=IllegalArgumentException.class) | ||
20 | public void isNullListThrowingException() { | ||
21 | List<Integer> sampleList = Arrays.asList(); | ||
22 | Lists.<Integer>mirrored(sampleList); | ||
23 | } | ||
24 | |||
25 | @Test | ||
26 | public void isListMirrored() { | ||
27 | List<Integer> sampleList = Arrays.asList(1,2,3,4,5); | ||
28 | List<Integer> expected = Arrays.asList(1,2,3,4,5,4,3,2,1); | ||
29 | |||
30 | assertEquals(expected, Lists.<Integer>mirrored(sampleList)); | ||
31 | } | ||
32 | } | ||
diff --git a/test/ch/epfl/xblast/namecheck/NameCheck02.java b/test/ch/epfl/xblast/namecheck/NameCheck02.java new file mode 100644 index 0000000..978526e --- /dev/null +++ b/test/ch/epfl/xblast/namecheck/NameCheck02.java | |||
@@ -0,0 +1,60 @@ | |||
1 | package ch.epfl.xblast.namecheck; | ||
2 | |||
3 | import java.util.List; | ||
4 | |||
5 | import ch.epfl.cs108.Sq; | ||
6 | import ch.epfl.xblast.Cell; | ||
7 | import ch.epfl.xblast.Lists; | ||
8 | import ch.epfl.xblast.server.Block; | ||
9 | import ch.epfl.xblast.server.Board; | ||
10 | import ch.epfl.xblast.server.Ticks; | ||
11 | |||
12 | /** | ||
13 | * Classe abstraite utilisant tous les éléments de l'étape 2, pour essayer de | ||
14 | * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est | ||
15 | * pas un test unitaire, et n'a pas pour but d'être exécuté! | ||
16 | */ | ||
17 | |||
18 | abstract class NameCheck02 { | ||