aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/server/Player.java38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/ch/epfl/xblast/server/Player.java b/src/ch/epfl/xblast/server/Player.java
index 668b948..8ab4cc6 100644
--- a/src/ch/epfl/xblast/server/Player.java
+++ b/src/ch/epfl/xblast/server/Player.java
@@ -12,6 +12,7 @@ import java.util.Objects;
12/** 12/**
13 * Player. 13 * Player.
14 * 14 *
15 * @author Pacien TRAN-GIRARD (261948)
15 * @author Timothée FLOURE (257420) 16 * @author Timothée FLOURE (257420)
16 */ 17 */
17public final class Player { 18public final class Player {
@@ -128,12 +129,36 @@ public final class Player {
128 } 129 }
129 } 130 }
130 131
132 private static final Direction DEFAULT_DIRECTION = Direction.S;
133
131 private final PlayerID id; 134 private final PlayerID id;
132 private final Sq<LifeState> lifeStates; 135 private final Sq<LifeState> lifeStates;
133 private final Sq<DirectedPosition> directedPos; 136 private final Sq<DirectedPosition> directedPos;
134 private final int maxBombs; 137 private final int maxBombs;
135 private final int bombRange; 138 private final int bombRange;
136 139
140 private static Sq<LifeState> buildDefaultLifeStateSequence(int lives) {
141 LifeState invulnerability = new LifeState(
142 ArgumentChecker.requireNonNegative(lives),
143 LifeState.State.INVULNERABLE
144 );
145 LifeState vulnerability = new LifeState(
146 ArgumentChecker.requireNonNegative(lives),
147 LifeState.State.VULNERABLE
148 );
149
150 return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerability).concat(Sq.constant(vulnerability));
151 }
152
153 private static Sq<DirectedPosition> buildDefaultDirectedPositionSequence(Cell pos) {
154 DirectedPosition dp = new DirectedPosition(
155 SubCell.centralSubCellOf(Objects.requireNonNull(pos)),
156 Player.DEFAULT_DIRECTION
157 );
158
159 return DirectedPosition.stopped(dp);
160 }
161
137 /** 162 /**
138 * Instanciates a new Player. 163 * Instanciates a new Player.
139 * 164 *
@@ -165,12 +190,13 @@ public final class Player {
165 * @throws NullPointerExeption 190 * @throws NullPointerExeption
166 */ 191 */
167 public Player(PlayerID id, int lives, Cell position, int maxBombs, int bombRange) { 192 public Player(PlayerID id, int lives, Cell position, int maxBombs, int bombRange) {
168 DirectedPosition newDirectedPosition = new DirectedPosition(SubCell.centralSubCellOf(Objects.requireNonNull(position)), Direction.S); 193 this(
169 DirectedPosition directedPositionSequence = DirectedPosition.stopped(newDirectedPos); 194 id,
170 LifeState invulnerability = new LifeState(ArgumentChecker.requireNonNegative(lives), LifeState.State.INVULNERABLE); 195 Player.buildDefaultLifeStateSequence(lives),
171 LifeState vulnerability = new LifeState(ArgumentChecker.requireNonNegative(lives), LifeState.State.VULNERABLE); 196 Player.buildDefaultDirectedPositionSequence(position),
172 Sq<LifeState> lifeStateSequence = Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerability).concat(Sq.constant(vulnerability)); 197 maxBombs,
173 this.Player(id, lifeStateSequence,directedPositionSequence, maxBombs, bombRange); 198 bombRange
199 );
174 } 200 }
175 201
176 /** 202 /**