aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ch/epfl/xblast/ArgumentChecker.java4
-rw-r--r--src/ch/epfl/xblast/PlayerID.java2
-rw-r--r--src/ch/epfl/xblast/server/Bomb.java32
-rw-r--r--src/ch/epfl/xblast/server/Player.java52
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck03.java13
5 files changed, 55 insertions, 48 deletions
diff --git a/src/ch/epfl/xblast/ArgumentChecker.java b/src/ch/epfl/xblast/ArgumentChecker.java
index a567fbb..311807e 100644
--- a/src/ch/epfl/xblast/ArgumentChecker.java
+++ b/src/ch/epfl/xblast/ArgumentChecker.java
@@ -7,12 +7,13 @@ package ch.epfl.xblast;
7 * @author Timothée FLOURE (257420) 7 * @author Timothée FLOURE (257420)
8 */ 8 */
9public final class ArgumentChecker { 9public final class ArgumentChecker {
10
10 /** 11 /**
11 * Returns the given value if it is non-negative. 12 * Returns the given value if it is non-negative.
12 * 13 *
13 * @param value the tested value 14 * @param value the tested value
14 * @throws IllegalArgumentException if the value is inferior to 0
15 * @return the given value if non-negative 15 * @return the given value if non-negative
16 * @throws IllegalArgumentException if the value is inferior to 0
16 */ 17 */
17 public static int requireNonNegative(int value) { 18 public static int requireNonNegative(int value) {
18 if (value >= 0) { 19 if (value >= 0) {
@@ -21,4 +22,5 @@ public final class ArgumentChecker {
21 throw new IllegalArgumentException(); 22 throw new IllegalArgumentException();
22 } 23 }
23 } 24 }
25
24} 26}
diff --git a/src/ch/epfl/xblast/PlayerID.java b/src/ch/epfl/xblast/PlayerID.java
index bb77405..c2c5c58 100644
--- a/src/ch/epfl/xblast/PlayerID.java
+++ b/src/ch/epfl/xblast/PlayerID.java
@@ -7,8 +7,10 @@ package ch.epfl.xblast;
7 * @author Timothée FLOURE (257420) 7 * @author Timothée FLOURE (257420)
8 */ 8 */
9public enum PlayerID { 9public enum PlayerID {
10
10 PLAYER_1, 11 PLAYER_1,
11 PLAYER_2, 12 PLAYER_2,
12 PLAYER_3, 13 PLAYER_3,
13 PLAYER_4 14 PLAYER_4
15
14} 16}
diff --git a/src/ch/epfl/xblast/server/Bomb.java b/src/ch/epfl/xblast/server/Bomb.java
index 4b89752..12e8888 100644
--- a/src/ch/epfl/xblast/server/Bomb.java
+++ b/src/ch/epfl/xblast/server/Bomb.java
@@ -1,14 +1,14 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3import ch.epfl.xblast.PlayerID;
4import ch.epfl.xblast.Cell;
5import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
6import ch.epfl.xblast.ArgumentChecker; 4import ch.epfl.xblast.ArgumentChecker;
5import ch.epfl.xblast.Cell;
7import ch.epfl.xblast.Direction; 6import ch.epfl.xblast.Direction;
7import ch.epfl.xblast.PlayerID;
8 8
9import java.util.Objects;
10import java.util.List;
11import java.util.ArrayList; 9import java.util.ArrayList;
10import java.util.List;
11import java.util.Objects;
12 12
13/** 13/**
14 * A Bomb. 14 * A Bomb.
@@ -17,6 +17,7 @@ import java.util.ArrayList;
17 * @author Timothée FLOURE (257420) 17 * @author Timothée FLOURE (257420)
18 */ 18 */
19public final class Bomb { 19public final class Bomb {
20
20 private PlayerID ownerId; 21 private PlayerID ownerId;
21 private Cell position; 22 private Cell position;
22 private Sq<Integer> fuseLengths; 23 private Sq<Integer> fuseLengths;
@@ -26,18 +27,20 @@ public final class Bomb {
26 * Generates one arm of explosion. 27 * Generates one arm of explosion.
27 */ 28 */
28 private Sq<Sq<Cell>> explosionArmTowards(Direction dir) { 29 private Sq<Sq<Cell>> explosionArmTowards(Direction dir) {
29 return Sq.constant( Sq.iterate(position, position -> position.neighbor(dir)).limit(range)).limit(Ticks.EXPLOSION_TICKS); 30 return Sq
31 .constant(Sq.iterate(position, position -> position.neighbor(dir)).limit(range))
32 .limit(Ticks.EXPLOSION_TICKS);
30 } 33 }
31 34
32 /** 35 /**
33 * Instantiates a new Bomb. 36 * Instantiates a new Bomb.
34 * 37 *
35 * @param ownerId id of the owner of the bomb 38 * @param ownerId id of the owner of the bomb
36 * @param position position of the bomb 39 * @param position position of the bomb
37 * @param fuseLengths length of the bomb's fuse 40 * @param fuseLengths length of the bomb's fuse
38 * @param range range of the bomb 41 * @param range range of the bomb
39 * @throws IllegalArgumentException if range is negative or fuseLenghts is empty 42 * @throws IllegalArgumentException if range is negative or fuseLenghts is empty
40 * @throws NullPointerException if ownerId, position or fuseLengths is null 43 * @throws NullPointerException if ownerId, position or fuseLengths is null
41 */ 44 */
42 public Bomb(PlayerID ownerId, Cell position, Sq<Integer> fuseLengths, int range) { 45 public Bomb(PlayerID ownerId, Cell position, Sq<Integer> fuseLengths, int range) {
43 this.ownerId = Objects.requireNonNull(ownerId); 46 this.ownerId = Objects.requireNonNull(ownerId);
@@ -53,15 +56,15 @@ public final class Bomb {
53 /** 56 /**
54 * Instantiates a new Bomb. 57 * Instantiates a new Bomb.
55 * 58 *
56 * @param ownerId id of the owner of the bomb 59 * @param ownerId id of the owner of the bomb
57 * @param position position of the bomb 60 * @param position position of the bomb
58 * @param fuseLength length of the bomb's fuse 61 * @param fuseLength length of the bomb's fuse
59 * @param range range of the bomb 62 * @param range range of the bomb
60 * @throws IllegalArgumentException if range or fuseLengths is negative 63 * @throws IllegalArgumentException if range or fuseLengths is negative
61 * @throws NullPointerException if ownerId, position or fuseLengths is null 64 * @throws NullPointerException if ownerId, position or fuseLengths is null
62 */ 65 */
63 public Bomb(PlayerID ownerId, Cell position, int fuseLength, int range) { 66 public Bomb(PlayerID ownerId, Cell position, int fuseLength, int range) {
64 this(ownerId, position, Sq.iterate(fuseLength, fl -> fl - 1 ), range); 67 this(ownerId, position, Sq.iterate(fuseLength, fl -> fl - 1), range);
65 } 68 }
66 69
67 /** 70 /**
@@ -109,4 +112,5 @@ public final class Bomb {
109 } 112 }
110 return explosion; 113 return explosion;
111 } 114 }
115
112} 116}
diff --git a/src/ch/epfl/xblast/server/Player.java b/src/ch/epfl/xblast/server/Player.java
index 0548125..7b5ac26 100644
--- a/src/ch/epfl/xblast/server/Player.java
+++ b/src/ch/epfl/xblast/server/Player.java
@@ -1,11 +1,7 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3import ch.epfl.xblast.ArgumentChecker;
4import ch.epfl.xblast.Direction;
5import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.SubCell;
7import ch.epfl.xblast.PlayerID;
8import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.*;
9 5
10import java.util.Objects; 6import java.util.Objects;
11 7
@@ -16,10 +12,12 @@ import java.util.Objects;
16 * @author Timothée FLOURE (257420) 12 * @author Timothée FLOURE (257420)
17 */ 13 */
18public final class Player { 14public final class Player {
15
19 /** 16 /**
20 * The life state of a player. 17 * The life state of a player.
21 */ 18 */
22 public static final class LifeState { 19 public static final class LifeState {
20
23 /** 21 /**
24 * Enum containing all the possible life states. 22 * Enum containing all the possible life states.
25 */ 23 */
@@ -65,13 +63,15 @@ public final class Player {
65 public boolean canMove() { 63 public boolean canMove() {
66 return (state() == State.INVULNERABLE || state() == State.VULNERABLE); 64 return (state() == State.INVULNERABLE || state() == State.VULNERABLE);
67 } 65 }
66
68 } 67 }
69 68
70 /** 69 /**
71 * The "directed" position of a player. 70 * The "directed" position of a player.
72 */ 71 */
73 public static final class DirectedPosition { 72 public static final class DirectedPosition {
74 private final SubCell position; 73
74 private final SubCell position;
75 private final Direction direction; 75 private final Direction direction;
76 76
77 /** 77 /**
@@ -91,7 +91,7 @@ public final class Player {
91 /** 91 /**
92 * Instantiates a new DirectedPos 92 * Instantiates a new DirectedPos
93 * 93 *
94 * @param position the position of the player 94 * @param position the position of the player
95 * @param direction the direction of the player 95 * @param direction the direction of the player
96 * @throws IllegalArgumentException if position or direction is null 96 * @throws IllegalArgumentException if position or direction is null
97 */ 97 */
@@ -122,11 +122,12 @@ public final class Player {
122 } 122 }
123 123
124 /** 124 /**
125 * @return a new directed position with the previous position and the given direction 125 * @return a new directed position with the previous position and the given direction
126 */ 126 */
127 public DirectedPosition withDirection(Direction newDirection) { 127 public DirectedPosition withDirection(Direction newDirection) {
128 return new DirectedPosition(position, newDirection); 128 return new DirectedPosition(position, newDirection);
129 } 129 }
130
130 } 131 }
131 132
132 /** 133 /**
@@ -156,7 +157,7 @@ public final class Player {
156 LifeState.State.VULNERABLE 157 LifeState.State.VULNERABLE
157 );