aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/Lists.java23
-rw-r--r--src/ch/epfl/xblast/SubCell.java2
-rw-r--r--src/ch/epfl/xblast/server/Board.java5
-rw-r--r--src/ch/epfl/xblast/server/Bomb.java8
-rw-r--r--src/ch/epfl/xblast/server/GameState.java10
-rw-r--r--src/ch/epfl/xblast/server/painter/BlockImage.java6
-rw-r--r--src/ch/epfl/xblast/server/painter/BoardPainter.java26
-rw-r--r--src/ch/epfl/xblast/server/painter/ExplosionPainter.java30
-rw-r--r--src/ch/epfl/xblast/server/painter/PlayerPainter.java86
9 files changed, 137 insertions, 59 deletions
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java
index 4cff795..b943162 100644
--- a/src/ch/epfl/xblast/Lists.java
+++ b/src/ch/epfl/xblast/Lists.java
@@ -13,6 +13,29 @@ import java.util.stream.Stream;
13public final class Lists { 13public final class Lists {
14 14
15 /** 15 /**
16 * Returns an immutable copy of a list.
17 *
18 * @param l a list
19 * @param <T> the element type
20 * @return the immutable list
21 */
22 public static <T> List<T> immutableList(List<T> l) {
23 return Collections.unmodifiableList(new ArrayList<>(l));
24 }
25
26 /**
27 * Returns an immutable copy of a map.
28 *
29 * @param m a mab
30 * @param <K> the key type
31 * @param <V> the value type
32 * @return the immutable copy
33 */
34 public static <K, V> Map<K, V> immutableMap(Map<K, V> m) {
35 return Collections.unmodifiableMap(new HashMap<>(m));
36 }
37
38 /**
16 * Returns a symmetric version of the list, without repeating the last element of the input list. 39 * Returns a symmetric version of the list, without repeating the last element of the input list.
17 * For instance, mirrored([kay]) will return [kayak]. 40 * For instance, mirrored([kay]) will return [kayak].
18 * 41 *
diff --git a/src/ch/epfl/xblast/SubCell.java b/src/ch/epfl/xblast/SubCell.java
index 51cbbb4..4278fab 100644
--- a/src/ch/epfl/xblast/SubCell.java
+++ b/src/ch/epfl/xblast/SubCell.java
@@ -31,7 +31,7 @@ public final class SubCell {
31 /** 31 /**
32 * The coordinates of the SubCell. 32 * The coordinates of the SubCell.
33 */ 33 */
34 private int x, y; 34 private final int x, y;
35 35
36 /** 36 /**
37 * Instantiates a new SubCell with the given coordinates. 37 * Instantiates a new SubCell with the given coordinates.
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java
index a18422a..4519781 100644
--- a/src/ch/epfl/xblast/server/Board.java
+++ b/src/ch/epfl/xblast/server/Board.java
@@ -4,7 +4,6 @@ import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.Cell; 4import ch.epfl.xblast.Cell;
5import ch.epfl.xblast.Lists; 5import ch.epfl.xblast.Lists;
6 6
7import java.util.ArrayList;
8import java.util.Collection; 7import java.util.Collection;
9import java.util.Collections; 8import java.util.Collections;
10import java.util.List; 9import java.util.List;
@@ -41,7 +40,7 @@ public final class Board {
41 /** 40 /**
42 * List containing all the blocks of the board. 41 * List containing all the blocks of the board.
43 */ 42 */
44 private List<Sq<Block>> blocks; 43 private final List<Sq<Block>> blocks;
45 44
46 /** 45 /**
47 * Instantiates a new Board with the given sequence of blocks. 46 * Instantiates a new Board with the given sequence of blocks.
@@ -53,7 +52,7 @@ public final class Board {
53 if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE) 52 if (blocks == null || blocks.size() != BLOCKS_LIST_SIZE)
54 throw new IllegalArgumentException(); 53 throw new IllegalArgumentException();
55 54
56 this.blocks = new ArrayList<>(blocks); 55 this.blocks = Lists.immutableList(blocks);
57 } 56 }
58 57
59 /** 58 /**
diff --git a/src/ch/epfl/xblast/server/Bomb.java b/src/ch/epfl/xblast/server/Bomb.java
index 535573f..57c271f 100644
--- a/src/ch/epfl/xblast/server/Bomb.java
+++ b/src/ch/epfl/xblast/server/Bomb.java
@@ -28,22 +28,22 @@ public final class Bomb {
28 /** 28 /**
29 * Owner of the Bomb. 29 * Owner of the Bomb.
30 */ 30 */
31 private PlayerID ownerId; 31 private final PlayerID ownerId;
32 32
33 /** 33 /**
34 * Position of the Bomb. 34 * Position of the Bomb.
35 */ 35 */
36 private Cell position; 36 private final Cell position;
37 37
38 /** 38 /**
39 * Fuse of the Bomb. 39 * Fuse of the Bomb.
40 */ 40 */
41 private Sq<Integer> fuseLengths; 41 private final Sq<Integer> fuseLengths;
42 42
43 /** 43 /**
44 * Range of the Bomb. 44 * Range of the Bomb.
45 */ 45 */
46 private int range; 46 private final int range;
47 47
48 /** 48 /**
49 * Instantiates a new Bomb. 49 * Instantiates a new Bomb.
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index 44fd5d1..abd07b3 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -52,7 +52,7 @@ public final class GameState {
52 * @param players list of the players 52 * @param players list of the players
53 */ 53 */
54 public GameState(Board board, List<Player> players) { 54 public GameState(Board board, List<Player> players) {
55 this(0, board, players, new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); 55 this(0, board, players, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
56 } 56 }
57 57
58 /** 58 /**
@@ -72,11 +72,11 @@ public final class GameState {
72 this.board = Objects.requireNonNull(board); 72 this.board = Objects.requireNonNull(board);
73 73
74 if (players.size() != PlayerID.values().length) throw new IllegalArgumentException(); 74 if (players.size() != PlayerID.values().length) throw new IllegalArgumentException();
75 this.players = new ArrayList<>(players); 75 this.players = Lists.immutableList(players);
76 76
77 this.bombs = new ArrayList<>(Objects.requireNonNull(bombs)); 77 this.bombs = Lists.immutableList(Objects.requireNonNull(bombs));
78 this.explosions = new ArrayList<>(Objects.requireNonNull(explosions)); 78 this.explosions = Lists.immutableList(Objects.requireNonNull(explosions));
79 this.blasts = new ArrayList<>(Objects.requireNonNull(blasts)); 79 this.blasts = Lists.immutableList(Objects.requireNonNull(blasts));
80 } 80 }
81 81
82 /** 82 /**
diff --git a/src/ch/epfl/xblast/server/painter/BlockImage.java b/src/ch/epfl/xblast/server/painter/BlockImage.java
index d5fa593..85a44be 100644
--- a/src/ch/epfl/xblast/server/painter/BlockImage.java
+++ b/src/ch/epfl/xblast/server/painter/BlockImage.java
@@ -1,7 +1,10 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3/** 3/**
4 * @author Timothée FLOURE (257420 4 * Block images enumeration.
5 *
6 * @author Timothée FLOURE (257420)
7 * @author Pacien TRAN-GIRARD (261948)
5 */ 8 */
6public enum BlockImage { 9public enum BlockImage {
7 10
@@ -39,4 +42,5 @@ public enum BlockImage {
39 * Bomb Range Bonus. 42 * Bomb Range Bonus.
40 */ 43 */
41 BONUS_RANGE 44 BONUS_RANGE
45
42} 46}
diff --git a/src/ch/epfl/xblast/server/painter/BoardPainter.java b/src/ch/epfl/xblast/server/painter/BoardPainter.java
index 69af129..34d0974 100644
--- a/src/ch/epfl/xblast/server/painter/BoardPainter.java
+++ b/src/ch/epfl/xblast/server/painter/BoardPainter.java
@@ -1,12 +1,19 @@
1package ch.epfl.xblast.server.painter; 1package ch.epfl.xblast.server.painter;
2 2
3import ch.epfl.xblast.*; 3import ch.epfl.xblast.Cell;
4import ch.epfl.xblast.server.*; 4import ch.epfl.xblast.Direction;
5import ch.epfl.xblast.Lists;
6import ch.epfl.xblast.server.Block;
7import ch.epfl.xblast.server.Board;
5 8
9import java.util.Collections;
6import java.util.Map; 10import java.util.Map;
7 11
8/** 12/**
13 * Board painter.
14 *
9 * @author Timothée FLOURE (257420) 15 * @author Timothée FLOURE (257420)
16 * @author Pacien TRAN-GIRARD (261948)
10 */ 17 */
11public final class BoardPainter { 18public final class BoardPainter {
12 19
@@ -16,11 +23,11 @@ public final class BoardPainter {
16 /** 23 /**
17 * Instantiates a new BoardPainter. 24 * Instantiates a new BoardPainter.
18 * 25 *
19 * @param blocksMap map linking block to the images 26 * @param blocksMap map linking block to the images
20 * @param shadowedFreeBlock a "shadowed" block image 27 * @param shadowedFreeBlock a "shadowed" block image
21 */ 28 */
22 public BoardPainter(Map<Block, BlockImage> blocksMap, BlockImage shadowedFreeBlock ) { 29 public BoardPainter(Map<Block, BlockImage> blocksMap, BlockImage shadowedFreeBlock) {
23 this.blocksMap = blocksMap; 30 this.blocksMap = Lists.immutableMap(blocksMap);
24 this.shadowedFreeBlock = shadowedFreeBlock; 31 this.shadowedFreeBlock = shadowedFreeBlock;
25 } 32 }
26 33
@@ -28,13 +35,14 @@ public final class BoardPai