aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-04-09 21:51:38 +0200
committerPacien TRAN-GIRARD2016-04-09 21:51:38 +0200
commit22f54da84e8e7e7a52fbc418ac6f168aff77997a (patch)
tree8775e11754d74f5e19ed0390074b5d8ac45f38b6 /src/ch/epfl
parentec46e380aca1c949ba18b90144597b521dc6a64b (diff)
downloadxblast-22f54da84e8e7e7a52fbc418ac6f168aff77997a.tar.gz
Fix Player and Bomb specific test failures
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/server/Bomb.java19
-rw-r--r--src/ch/epfl/xblast/server/Player.java22
2 files changed, 25 insertions, 16 deletions
diff --git a/src/ch/epfl/xblast/server/Bomb.java b/src/ch/epfl/xblast/server/Bomb.java
index c1a6b12..dd26ddd 100644
--- a/src/ch/epfl/xblast/server/Bomb.java
+++ b/src/ch/epfl/xblast/server/Bomb.java
@@ -22,6 +22,17 @@ public final class Bomb {
22 22
23 private static final UnaryOperator<Integer> FUSE_STEP_FUNCTION = fl -> fl - 1; 23 private static final UnaryOperator<Integer> FUSE_STEP_FUNCTION = fl -> fl - 1;
24 24
25 /**
26 * Builds and returns a new fuse sequence of given length.
27 *
28 * @param fuseLength the fuse length
29 * @return the fuse sequence
30 */
31 private static Sq<Integer> buildFuseSequence(int fuseLength) {
32 int fl = ArgumentChecker.requireNonNegative(fuseLength);
33 return Sq.iterate(fl, Bomb.FUSE_STEP_FUNCTION).limit(fl);
34 }
35
25 private PlayerID ownerId; 36 private PlayerID ownerId;
26 private Cell position; 37 private Cell position;
27 private Sq<Integer> fuseLengths; 38 private Sq<Integer> fuseLengths;
@@ -49,11 +60,7 @@ public final class Bomb {
49 public Bomb(PlayerID ownerId, Cell position, Sq<Integer> fuseLengths, int range) { 60 public Bomb(PlayerID ownerId, Cell position, Sq<Integer> fuseLengths, int range) {
50 this.ownerId = Objects.requireNonNull(ownerId); 61 this.ownerId = Objects.requireNonNull(ownerId);
51 this.position = Objects.requireNonNull(position); 62 this.position = Objects.requireNonNull(position);
52 63 this.fuseLengths = ArgumentChecker.requireNonEmpty(fuseLengths);
53 this.fuseLengths = Objects.requireNonNull(fuseLengths);
54 if (this.fuseLengths.isEmpty())
55 throw new IllegalArgumentException();
56
57 this.range = ArgumentChecker.requireNonNegative(range); 64 this.range = ArgumentChecker.requireNonNegative(range);
58 } 65 }
59 66
@@ -68,7 +75,7 @@ public final class Bomb {
68 * @throws NullPointerException if ownerId, position or fuseLengths is null 75 * @throws NullPointerException if ownerId, position or fuseLengths is null
69 */ 76 */
70 public Bomb(PlayerID ownerId, Cell position, int fuseLength, int range) { 77 public Bomb(PlayerID ownerId, Cell position, int fuseLength, int range) {
71 this(ownerId, position, Sq.iterate(fuseLength, Bomb.FUSE_STEP_FUNCTION), range); 78 this(ownerId, position, Bomb.buildFuseSequence(fuseLength), range);
72 } 79 }
73 80
74 /** 81 /**
diff --git a/src/ch/epfl/xblast/server/Player.java b/src/ch/epfl/xblast/server/Player.java
index afff209..e8f3145 100644
--- a/src/ch/epfl/xblast/server/Player.java
+++ b/src/ch/epfl/xblast/server/Player.java
@@ -40,7 +40,7 @@ public final class Player {
40 */ 40 */
41 public LifeState(int lives, State state) { 41 public LifeState(int lives, State state) {
42 this.lives = ArgumentChecker.requireNonNegative(lives); 42 this.lives = ArgumentChecker.requireNonNegative(lives);
43 this.state = state; 43 this.state = Objects.requireNonNull(state);
44 } 44 }
45 45
46 /** 46 /**
@@ -166,16 +166,18 @@ public final class Player {
166 * @return the sequence 166 * @return the sequence
167 */ 167 */
168 private static Sq<LifeState> buildDefaultLifeStateSequence(int lives) { 168 private static Sq<LifeState> buildDefaultLifeStateSequence(int lives) {
169 LifeState invulnerability = new LifeState( 169 int l = ArgumentChecker.requireNonNegative(lives);
170 ArgumentChecker.requireNonNegative(lives), 170
171 LifeState.State.INVULNERABLE 171 switch (l) {
172 ); 172 case 0:
173 LifeState vulnerability = new LifeState( 173 return Sq.constant(new LifeState(l, LifeState.State.DEAD));
174 ArgumentChecker.requireNonNegative(lives),
175 LifeState.State.VULNERABLE
176 );
177 174
178 return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS, invulnerability).concat(Sq.constant(vulnerability)); 175 default:
176 LifeState invulnerability = new LifeState(l, LifeState.State.INVULNERABLE);
177 LifeState vulnerability = new LifeState(l, LifeState.State.VULNERABLE);
178 return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS, invulnerability).concat(Sq.constant(vulnerability));
179
180 }
179 } 181 }
180 182
181 /** 183 /**