From 2c5bd508c1573a3bbc334dc121e3c4fca322b84c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 7 Mar 2016 16:40:53 +0100 Subject: Fix default life-state and directed position sequences Player constructor --- src/ch/epfl/xblast/server/Player.java | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/ch/epfl') 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; /** * Player. * + * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ public final class Player { @@ -128,12 +129,36 @@ public final class Player { } } + private static final Direction DEFAULT_DIRECTION = Direction.S; + private final PlayerID id; private final Sq lifeStates; private final Sq directedPos; private final int maxBombs; private final int bombRange; + private static Sq buildDefaultLifeStateSequence(int lives) { + LifeState invulnerability = new LifeState( + ArgumentChecker.requireNonNegative(lives), + LifeState.State.INVULNERABLE + ); + LifeState vulnerability = new LifeState( + ArgumentChecker.requireNonNegative(lives), + LifeState.State.VULNERABLE + ); + + return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerability).concat(Sq.constant(vulnerability)); + } + + private static Sq buildDefaultDirectedPositionSequence(Cell pos) { + DirectedPosition dp = new DirectedPosition( + SubCell.centralSubCellOf(Objects.requireNonNull(pos)), + Player.DEFAULT_DIRECTION + ); + + return DirectedPosition.stopped(dp); + } + /** * Instanciates a new Player. * @@ -165,12 +190,13 @@ public final class Player { * @throws NullPointerExeption */ public Player(PlayerID id, int lives, Cell position, int maxBombs, int bombRange) { - DirectedPosition newDirectedPosition = new DirectedPosition(SubCell.centralSubCellOf(Objects.requireNonNull(position)), Direction.S); - DirectedPosition directedPositionSequence = DirectedPosition.stopped(newDirectedPos); - LifeState invulnerability = new LifeState(ArgumentChecker.requireNonNegative(lives), LifeState.State.INVULNERABLE); - LifeState vulnerability = new LifeState(ArgumentChecker.requireNonNegative(lives), LifeState.State.VULNERABLE); - Sq lifeStateSequence = Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerability).concat(Sq.constant(vulnerability)); - this.Player(id, lifeStateSequence,directedPositionSequence, maxBombs, bombRange); + this( + id, + Player.buildDefaultLifeStateSequence(lives), + Player.buildDefaultDirectedPositionSequence(position), + maxBombs, + bombRange + ); } /** -- cgit v1.2.3