diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | conventions.md | 41 | ||||
-rw-r--r-- | lib/sq.jar | bin | 0 -> 6651 bytes | |||
-rw-r--r-- | src/ch/epfl/xblast/Direction.java | 2 | ||||
-rw-r--r-- | src/ch/epfl/xblast/Lists.java | 49 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Block.java | 11 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 133 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Ticks.java | 32 | ||||
-rw-r--r-- | test/ch/epfl/xblast/CellTest.java | 29 | ||||
-rw-r--r-- | test/ch/epfl/xblast/DirectionTest.java | 2 | ||||
-rw-r--r-- | test/ch/epfl/xblast/ListsTest.java | 49 | ||||
-rw-r--r-- | test/ch/epfl/xblast/SubCellTest.java | 25 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck01.java | 11 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck02.java | 9 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BlockTest.java | 7 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BoardTest.java | 145 |
16 files changed, 356 insertions, 191 deletions
@@ -54,7 +54,7 @@ local.properties | |||
54 | .mtj.tmp/ | 54 | .mtj.tmp/ |
55 | 55 | ||
56 | # Package Files # | 56 | # Package Files # |
57 | *.jar | 57 | #*.jar |
58 | *.war | 58 | *.war |
59 | *.ear | 59 | *.ear |
60 | 60 | ||
diff --git a/conventions.md b/conventions.md new file mode 100644 index 0000000..875292f --- /dev/null +++ b/conventions.md | |||
@@ -0,0 +1,41 @@ | |||
1 | Coding conventions | ||
2 | ================== | ||
3 | |||
4 | This document contains some syntactic and code format conventions for the current project and should be used as a | ||
5 | reference to enhance code uniformity. | ||
6 | |||
7 | |||
8 | Formatting | ||
9 | ---------- | ||
10 | |||
11 | Sources are formatted as defined in the `EPFL-PPO.xml` Eclipse format file. | ||
12 | |||
13 | |||
14 | Members ordering | ||
15 | ---------------- | ||
16 | |||
17 | Class (static) members are placed before object members. In each group, attributes are placed before methods. | ||
18 | Constructors are the first methods, and overridden parent methods the last ones. | ||
19 | |||
20 | |||
21 | Object/Class reference | ||
22 | ---------------------- | ||
23 | |||
24 | Methods and attributes are referenced using `this` for the current class, and by their class name for static | ||
25 | ones. | ||
26 | |||
27 | Static imports are avoided, except for JUnit tests. | ||
28 | |||
29 | |||
30 | Redundant type/scope | ||
31 | -------------------- | ||
32 | |||
33 | Use of the diamond notation is encouraged to avoid redundancy. | ||
34 | |||
35 | Unnecessary scope modifiers are avoided (ex: `public` in interfaces). | ||
36 | |||
37 | |||
38 | Unnecessary brackets | ||
39 | -------------------- | ||
40 | |||
41 | Unnecessary brackets in one to two line statements are avoided to simplify the reading of the control flow. | ||
diff --git a/lib/sq.jar b/lib/sq.jar new file mode 100644 index 0000000..44bbc9a --- /dev/null +++ b/lib/sq.jar | |||
Binary files differ | |||
diff --git a/src/ch/epfl/xblast/Direction.java b/src/ch/epfl/xblast/Direction.java index 700f9be..030038b 100644 --- a/src/ch/epfl/xblast/Direction.java +++ b/src/ch/epfl/xblast/Direction.java | |||
@@ -2,7 +2,7 @@ package ch.epfl.xblast; | |||
2 | 2 | ||
3 | /** | 3 | /** |
4 | * A Direction. | 4 | * A Direction. |
5 | * | 5 | * |
6 | * @author Pacien TRAN-GIRARD (261948) | 6 | * @author Pacien TRAN-GIRARD (261948) |
7 | * @author Timothée FLOURE (257420) | 7 | * @author Timothée FLOURE (257420) |
8 | */ | 8 | */ |
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index 096ceba..51e76b0 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java | |||
@@ -1,38 +1,47 @@ | |||
1 | package ch.epfl.xblast; | 1 | package ch.epfl.xblast; |
2 | 2 | ||
3 | import java.util.List; | ||
4 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
5 | import java.util.Collections; | 4 | import java.util.Collections; |
5 | import java.util.List; | ||
6 | import java.util.stream.Collectors; | ||
7 | import java.util.stream.Stream; | ||
6 | 8 | ||
7 | /** | 9 | /** |
10 | * Lists utility class providing common operations on lists. | ||
11 | * | ||
8 | * @author Pacien TRAN-GIRARD (261948) | 12 | * @author Pacien TRAN-GIRARD (261948) |
9 | * @author Timothée FLOURE (257420) | 13 | * @author Timothée FLOURE (257420) |
10 | */ | 14 | */ |
11 | public final class Lists { | 15 | public final class Lists { |
16 | |||
12 | /** | 17 | /** |
13 | * Return a sysmetric version of the list. | 18 | * Returns a reversed copy of the given list, leaving the original one unmodified. |
14 | * | 19 | * |
15 | * @param l the input list | 20 | * @param l the list to reverse |
21 | * @param <T> the type of the list's elements | ||
22 | * @return a reversed copy of the list. | ||
23 | */ | ||
24 | public static <T> List<T> reversed(List<T> l) { | ||
25 | List<T> r = new ArrayList<>(l); | ||
26 | Collections.reverse(r); | ||
27 | return r; | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Returns a symmetric version of the list, without repeating the last element of the input list. | ||
32 | * For instance, mirrored([kay]) will return [kayak]. | ||
33 | * | ||
34 | * @param l the input list | ||
35 | * @param <T> the type of the list's elements | ||
36 | * @return the mirrored list | ||
16 | * @throws IllegalArgumentException if the given list is empty | 37 | * @throws IllegalArgumentException if the given list is empty |
17 | * @return mirroredList the mirrored ilist | ||
18 | */ | 38 | */ |
19 | public static <T> List<T> mirrored(List<T> l) { | 39 | public static <T> List<T> mirrored(List<T> l) { |
20 | if (l.size() == 0) { | 40 | if (l == null || l.size() == 0) throw new IllegalArgumentException(); |
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 | 41 | ||
31 | Collections.reverse(rightSide); | 42 | return Stream |
32 | 43 | .concat(l.stream(), Lists.reversed(l).stream().skip(1)) | |
33 | mirroredList.addAll(l); | 44 | .collect(Collectors.toList()); |
34 | mirroredList.addAll(rightSide); | ||
35 | |||
36 | return mirroredList; | ||
37 | } | 45 | } |
46 | |||
38 | } | 47 | } |
diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java index 8268f33..409f68e 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java | |||
@@ -1,5 +1,11 @@ | |||
1 | package ch.epfl.xblast.server; | 1 | package ch.epfl.xblast.server; |
2 | 2 | ||
3 | /** | ||
4 | * A Block. | ||
5 | * | ||
6 | * @author Pacien TRAN-GIRARD (261948) | ||
7 | * @author Timothée FLOURE (257420) | ||
8 | */ | ||
3 | public enum Block { | 9 | public enum Block { |
4 | 10 | ||
5 | /** | 11 | /** |
@@ -41,11 +47,12 @@ public enum Block { | |||
41 | } | 47 | } |
42 | 48 | ||
43 | /** | 49 | /** |
44 | * Returns T(this block cast a shadow) | 50 | * Returns T(this block cast a shadow). |
45 | * | 51 | * |
46 | * @returns T(this block cast a shadow) | 52 | * @return T(this block cast a shadow) |
47 | */ | 53 | */ |
48 | public boolean castsShadow() { | 54 | public boolean castsShadow() { |
49 | return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; | 55 | return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; |
50 | } | 56 | } |
57 | |||
51 | } | 58 | } |
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java index fa91587..5e03671 100644 --- a/src/ch/epfl/xblast/server/Board.java +++ b/src/ch/epfl/xblast/server/Board.java | |||
@@ -1,31 +1,60 @@ | |||
1 | package ch.epfl.xblast.server; | 1 | package ch.epfl.xblast.server; |
2 | 2 | ||
3 | import java.util.List; | ||
4 | import java.util.ArrayList; | ||
5 | import ch.epfl.cs108.Sq; | 3 | import ch.epfl.cs108.Sq; |
4 | import ch.epfl.xblast.Cell; | ||
6 | import ch.epfl.xblast.Lists; | 5 | import ch.epfl.xblast.Lists; |
7 | 6 | ||
7 | import java.util.ArrayList; | ||
8 | import java.util.List; | ||
9 | |||
8 | /** | 10 | /** |
11 | * A two-dimensional Board in which the game takes place. | ||
12 | * | ||
9 | * @author Pacien TRAN-GIRARD (261948) | 13 | * @author Pacien TRAN-GIRARD (261948) |
10 | * @author Timothée FLOURE (257420) | 14 | * @author Timothée FLOURE (257420) |
11 | */ | 15 | */ |
12 | |||
13 | public final class Board { | 16 | public final class Board { |
17 | |||
18 | private static final int BLOCKS_LIST_SIZE = 195; | ||
19 | private static final int BOARD_ROWS = 13; | ||
20 | private static final int BOARD_COLUMNS = 15; | ||
21 | private static final int INNER_BOARD_ROWS = BOARD_ROWS - 2; | ||
22 | private static final int INNER_BOARD_COLUMNS = BOARD_COLUMNS - 2; | ||
23 | private static final int QUADRANT_ROWS = 6; | ||
24 | private static final int QUADRANT_COLUMNS = 7; | ||
25 | |||
26 | /** | ||
27 | * Throw an exception if the matrix does not have the given number of rows/columns. | ||
28 | * | ||
29 | * @param matrix the tested matrix | ||
30 | * @param rows the expected number of rows | ||