aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien2016-03-01 18:45:54 +0100
committerPacien2016-03-01 18:45:54 +0100
commit264fec2ec938a6c525ca6f569692118a8216ca19 (patch)
tree0cf7fe569b6de16c4bd4dc8776fb82dfeeda312e
parent45880b06c053e75e1778a598245015c65440a5bc (diff)
parentcc88afb9fe448b759966e94b07692fb6a154b2bf (diff)
downloadxblast-264fec2ec938a6c525ca6f569692118a8216ca19.tar.gz
Merge branch '02_board' into 'master' 02_board
02 board See merge request !1
-rw-r--r--.gitignore2
-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.java47
-rw-r--r--src/ch/epfl/xblast/server/Block.java58
-rw-r--r--src/ch/epfl/xblast/server/Board.java145
-rw-r--r--src/ch/epfl/xblast/server/Ticks.java41
-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.java51
-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.java63
-rw-r--r--test/ch/epfl/xblast/server/BlockTest.java38
-rw-r--r--test/ch/epfl/xblast/server/BoardTest.java166
15 files changed, 652 insertions, 28 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/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
new file mode 100644
index 0000000..51e76b0
--- /dev/null
+++ b/src/ch/epfl/xblast/Lists.java
@@ -0,0 +1,47 @@
1package ch.epfl.xblast;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.List;
6import java.util.stream.Collectors;
7import java.util.stream.Stream;
8
9/**
10 * Lists utility class providing common operations on lists.
11 *
12 * @author Pacien TRAN-GIRARD (261948)
13 * @author Timothée FLOURE (257420)
14 */
15public final class Lists {
16
17 /**
18 * Returns a reversed copy of the given list, leaving the original one unmodified.
19 *
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
37 * @throws IllegalArgumentException if the given list is empty
38 */
39 public static <T> List<T> mirrored(List<T> l) {
40 if (l == null || l.size() == 0) throw new IllegalArgumentException();
41
42 return Stream
43 .concat(l.stream(), Lists.reversed(l).stream().skip(1))
44 .collect(Collectors.toList());
45 }
46
47}
diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java
new file mode 100644
index 0000000..409f68e
--- /dev/null
+++ b/src/ch/epfl/xblast/server/Block.java
@@ -0,0 +1,58 @@
1package ch.epfl.xblast.server;
2
3/**
4 * A Block.
5 *
6 * @author Pacien TRAN-GIRARD (261948)
7 * @author Timothée FLOURE (257420)
8 */
9public enum Block {
10
11 /**
12 * 'Free' block, no wall.
13 */
14 FREE,
15
16 /**
17 * Indestructible block.
18 */
19 INDESTRUCTIBLE_WALL,
20
21 /**
22 * Destructible block.
23 */
24 DESTRUCTIBLE_WALL,
25
26 /**
27 * Crumbling Wall.
28 */
29 CRUMBLING_WALL;
30
31 /**
32 * Returns T(this block is free).
33 *
34 * @return T(this block is free)
35 */
36 public boolean isFree() {
37 return this == FREE;
38 }
39
40 /**
41 * Returns T(this block can host a player).
42 *
43 * @return T(this block can host a player)
44 */
45 public boolean canHostPlayer() {
46 return this.isFree();
47 }
48
49 /**
50 * Returns T(this block cast a shadow).
51 *
52 * @return T(this block cast a shadow)
53 */
54 public boolean castsShadow() {
55 return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL;
56 }
57
58}
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java
new file mode 100644
index 0000000..5e03671
--- /dev/null
+++ b/src/ch/epfl/xblast/server/Board.java
@@ -0,0 +1,145 @@
1package ch.epfl.xblast.server;
2
3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.Cell;
5import ch.epfl.xblast.Lists;
6
7import java.util.ArrayList;
8import java.util.List;
9
10/**
11 * A two-dimensional Board in which the game takes place.
12 *
13 * @author Pacien TRAN-GIRARD (261948)
14 * @author Timothée FLOURE (257420)
15 */
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
31 * @param columns the expected number of columns
32 * @throws IllegalArgumentException if the matrix does not comply with the given sizes.
33 */
34 private static void checkBlockMatrix(List<List<Block>> matrix, int rows, int columns) {
35 if (matrix == null || matrix.size() != rows)
36 throw new IllegalArgumentException();
37
38 for (int i = 0; i < rows; i++)
39 if (matrix.get(i).size() != columns)
40 throw new IllegalArgumentException();
41 }
42
43 /**
44 * List containing all the blocks of the board.
45 */
46 private List<Sq<Block>> blocks;
47
48 /**
49 * Instantiates a new Board with the given sequence of blocks.
50 *
51 * @param blocks sequence containing all the blocks of the Boards
52 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements
53 */
54 public Board(List<Sq<Block>> blocks) {
55 if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE)
56 throw new IllegalArgumentException();
57
58 this.blocks = blocks;
59 }
60
61 /**
62 * Build a new Board with the given Matrix.
63 *
64 * @param rows list containing all the rows
65 * @return a new Board built with given rows
66 * @throws IllegalArgumentException if rows is not BOARD_ROWS * BOARD_COLUMNS
67 */
68 public static Board ofRows(List<List<Block>> rows) {
69 checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS);
70 List<Sq<Block>> blocksSequence = new ArrayList<>();
71
72 for (List<Block> row : rows)
73 for (Block aRow : row)
74 blocksSequence.add(Sq.constant(aRow));
75
76 return new Board(blocksSequence);
77 }
78
79 /**
80 * Build a walled board filled with the given inner rows
81 *
82 * @param innerBlocks lists of the internal rows
83 * @return a new walled board filled with the given rows