aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch')
-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
5 files changed, 137 insertions, 90 deletions
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
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
14 /** 43 /**
15 * List containing all the blocks of the board. 44 * List containing all the blocks of the board.
16 */ 45 */
17 private List<Sq<Block>> blocks; 46 private List<Sq<Block>> blocks;
18 47
19 /** 48 /**
20 * Instanciates a new Board with the given sequence of blocks. 49 * Instantiates a new Board with the given sequence of blocks.
21 * 50 *
22 * @throws IllegalArgumentEception if the blocks is not composed of 195 elements 51 * @param blocks sequence containing all the blocks of the Boards
23 * @param blocks sequence conataining all the blocks of the Boards 52 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements
24 */ 53 */
25 public Board (List<Sq<Block>> blocks) { 54 public Board(List<Sq<Block>> blocks) {
26 if (blocks.size() != 195) { 55 if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE)
27 throw new IllegalArgumentException(); 56 throw new IllegalArgumentException();
28 } 57
29 this.blocks = blocks; 58 this.blocks = blocks;
30 } 59 }
31 60
@@ -33,90 +62,84 @@ public final class Board {
33 * Build a new Board with the given Matrix. 62 * Build a new Board with the given Matrix.
34 * 63 *
35 * @param rows list containing all the rows 64 * @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 65 * @return a new Board built with given rows
66 * @throws IllegalArgumentException if rows is not BOARD_ROWS * BOARD_COLUMNS
38 */ 67 */
39 public static Board ofRows(List<List<Block>> rows) { 68 public static Board ofRows(List<List<Block>> rows) {
40 if (rows.size() != 13) { 69 checkBlockMatrix(rows, BOARD_ROWS, BOARD_COLUMNS);
41 throw new IllegalArgumentException();
42 }
43
44 List<Sq<Block>> blocksSequence = new ArrayList<>(); 70 List<Sq<Block>> blocksSequence = new ArrayList<>();
45 71
46 for (int i = 0; i < rows.size(); i++) { 72 for (List<Block> row : rows)
47