aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--conventions.md41
-rw-r--r--lib/sq.jarbin0 -> 6651 bytes
-rw-r--r--src/ch/epfl/xblast/Direction.java2
-rw-r--r--src/ch/epfl/xblast/Lists.java49
-rw-r--r--src/ch/epfl/xblast/server/Block.java11
-rw-r--r--src/ch/epfl/xblast/server/Board.java133
-rw-r--r--src/ch/epfl/xblast/server/Ticks.java32
-rw-r--r--test/ch/epfl/xblast/CellTest.java29
-rw-r--r--test/ch/epfl/xblast/DirectionTest.java2
-rw-r--r--test/ch/epfl/xblast/ListsTest.java49
-rw-r--r--test/ch/epfl/xblast/SubCellTest.java25
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck01.java11
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck02.java9
-rw-r--r--test/ch/epfl/xblast/server/BlockTest.java7
-rw-r--r--test/ch/epfl/xblast/server/BoardTest.java145
16 files changed, 356 insertions, 191 deletions
diff --git a/.gitignore b/.gitignore
index 5a61770..de15d2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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 @@
1Coding conventions
2==================
3
4This document contains some syntactic and code format conventions for the current project and should be used as a
5reference to enhance code uniformity.
6
7
8Formatting
9----------
10
11Sources are formatted as defined in the `EPFL-PPO.xml` Eclipse format file.
12
13
14Members ordering
15----------------
16
17Class (static) members are placed before object members. In each group, attributes are placed before methods.
18Constructors are the first methods, and overridden parent methods the last ones.
19
20
21Object/Class reference
22----------------------
23
24Methods and attributes are referenced using `this` for the current class, and by their class name for static
25ones.
26
27Static imports are avoided, except for JUnit tests.
28
29
30Redundant type/scope
31--------------------
32
33Use of the diamond notation is encouraged to avoid redundancy.
34
35Unnecessary scope modifiers are avoided (ex: `public` in interfaces).
36
37
38Unnecessary brackets
39--------------------
40
41Unnecessary 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 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import java.util.List;
4import java.util.ArrayList; 3import java.util.ArrayList;
5import java.util.Collections; 4import java.util.Collections;
5import java.util.List;
6import java.util.stream.Collectors;
7import 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 */
11public final class Lists { 15public 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 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3/**
4 * A Block.
5 *
6 * @author Pacien TRAN-GIRARD (261948)
7 * @author Timothée FLOURE (257420)
8 */
3public enum Block { 9public 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 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3import java.util.List;
4import java.util.ArrayList;
5import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.Lists; 5import ch.epfl.xblast.Lists;
7 6
7import java.util.ArrayList;
8import 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
13public final class Board { 16public 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