From 69ec741acb840c444471579d53aafd94eae80795 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 7 Mar 2016 17:08:07 +0100 Subject: Reformat code --- src/ch/epfl/xblast/ArgumentChecker.java | 4 +- src/ch/epfl/xblast/PlayerID.java | 2 + src/ch/epfl/xblast/server/Bomb.java | 32 +++++++++------- src/ch/epfl/xblast/server/Player.java | 52 +++++++++++++------------- test/ch/epfl/xblast/namecheck/NameCheck03.java | 13 +++---- 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; * @author Timothée FLOURE (257420) */ public final class ArgumentChecker { + /** * Returns the given value if it is non-negative. * * @param value the tested value - * @throws IllegalArgumentException if the value is inferior to 0 * @return the given value if non-negative + * @throws IllegalArgumentException if the value is inferior to 0 */ public static int requireNonNegative(int value) { if (value >= 0) { @@ -21,4 +22,5 @@ public final class ArgumentChecker { throw new IllegalArgumentException(); } } + } 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; * @author Timothée FLOURE (257420) */ public enum PlayerID { + PLAYER_1, PLAYER_2, PLAYER_3, PLAYER_4 + } 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 @@ package ch.epfl.xblast.server; -import ch.epfl.xblast.PlayerID; -import ch.epfl.xblast.Cell; import ch.epfl.cs108.Sq; import ch.epfl.xblast.ArgumentChecker; +import ch.epfl.xblast.Cell; import ch.epfl.xblast.Direction; +import ch.epfl.xblast.PlayerID; -import java.util.Objects; -import java.util.List; import java.util.ArrayList; +import java.util.List; +import java.util.Objects; /** * A Bomb. @@ -17,6 +17,7 @@ import java.util.ArrayList; * @author Timothée FLOURE (257420) */ public final class Bomb { + private PlayerID ownerId; private Cell position; private Sq fuseLengths; @@ -26,18 +27,20 @@ public final class Bomb { * Generates one arm of explosion. */ private Sq> explosionArmTowards(Direction dir) { - return Sq.constant( Sq.iterate(position, position -> position.neighbor(dir)).limit(range)).limit(Ticks.EXPLOSION_TICKS); + return Sq + .constant(Sq.iterate(position, position -> position.neighbor(dir)).limit(range)) + .limit(Ticks.EXPLOSION_TICKS); } /** * Instantiates a new Bomb. * - * @param ownerId id of the owner of the bomb - * @param position position of the bomb + * @param ownerId id of the owner of the bomb + * @param position position of the bomb * @param fuseLengths length of the bomb's fuse - * @param range range of the bomb + * @param range range of the bomb * @throws IllegalArgumentException if range is negative or fuseLenghts is empty - * @throws NullPointerException if ownerId, position or fuseLengths is null + * @throws NullPointerException if ownerId, position or fuseLengths is null */ public Bomb(PlayerID ownerId, Cell position, Sq fuseLengths, int range) { this.ownerId = Objects.requireNonNull(ownerId); @@ -53,15 +56,15 @@ public final class Bomb { /** * Instantiates a new Bomb. * - * @param ownerId id of the owner of the bomb - * @param position position of the bomb + * @param ownerId id of the owner of the bomb + * @param position position of the bomb * @param fuseLength length of the bomb's fuse - * @param range range of the bomb + * @param range range of the bomb * @throws IllegalArgumentException if range or fuseLengths is negative - * @throws NullPointerException if ownerId, position or fuseLengths is null + * @throws NullPointerException if ownerId, position or fuseLengths is null */ public Bomb(PlayerID ownerId, Cell position, int fuseLength, int range) { - this(ownerId, position, Sq.iterate(fuseLength, fl -> fl - 1 ), range); + this(ownerId, position, Sq.iterate(fuseLength, fl -> fl - 1), range); } /** @@ -109,4 +112,5 @@ public final class Bomb { } return explosion; } + } 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 @@ package ch.epfl.xblast.server; -import ch.epfl.xblast.ArgumentChecker; -import ch.epfl.xblast.Direction; -import ch.epfl.xblast.Cell; -import ch.epfl.xblast.SubCell; -import ch.epfl.xblast.PlayerID; import ch.epfl.cs108.Sq; +import ch.epfl.xblast.*; import java.util.Objects; @@ -16,10 +12,12 @@ import java.util.Objects; * @author Timothée FLOURE (257420) */ public final class Player { + /** * The life state of a player. */ public static final class LifeState { + /** * Enum containing all the possible life states. */ @@ -65,13 +63,15 @@ public final class Player { public boolean canMove() { return (state() == State.INVULNERABLE || state() == State.VULNERABLE); } + } /** * The "directed" position of a player. */ public static final class DirectedPosition { - private final SubCell position; + + private final SubCell position; private final Direction direction; /** @@ -91,7 +91,7 @@ public final class Player { /** * Instantiates a new DirectedPos * - * @param position the position of the player + * @param position the position of the player * @param direction the direction of the player * @throws IllegalArgumentException if position or direction is null */ @@ -122,11 +122,12 @@ public final class Player { } /** - * @return a new directed position with the previous position and the given direction + * @return a new directed position with the previous position and the given direction */ public DirectedPosition withDirection(Direction newDirection) { return new DirectedPosition(position, newDirection); } + } /** @@ -156,7 +157,7 @@ public final class Player { LifeState.State.VULNERABLE ); - return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerability).concat(Sq.constant(vulnerability)); + return Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS, invulnerability).concat(Sq.constant(vulnerability)); } /** @@ -177,11 +178,11 @@ public final class Player { /** * Instantiates a new Player. * - * @param id the Player's id - * @param lifeStates a sequence of LifeState-s + * @param id the Player's id + * @param lifeStates a sequence of LifeState-s * @param directedPos a sequence of DirectedPosition-s - * @param maxBombs the maximum number of Bomb-s the Player can carry - * @param bombRange the range of the Bomb-s + * @param maxBombs the maximum number of Bomb-s the Player can carry + * @param bombRange the range of the Bomb-s * @throws IllegalArgumentException * @throws NullPointerException */ @@ -196,22 +197,22 @@ public final class Player { /** * Instantiates a new Player. * - * @param id the Player's id - * @param lives the number of lives of the Player - * @param position the starting position of the Player - * @param maxBombs the maximum number of Bomb-s the Player can carry + * @param id the Player's id + * @param lives the number of lives of the Player + * @param position the starting position of the Player + * @param maxBombs the maximum number of Bomb-s the Player can carry * @param bombRange the range of the Bomb-s * @throws IllegalArgumentException * @throws NullPointerException */ public Player(PlayerID id, int lives, Cell position, int maxBombs, int bombRange) { - this( - id, - Player.buildDefaultLifeStateSequence(lives), - Player.buildDefaultDirectedPositionSequence(position), - maxBombs, - bombRange - ); + this( + id, + Player.buildDefaultLifeStateSequence(lives), + Player.buildDefaultDirectedPositionSequence(position), + maxBombs, + bombRange + ); } /** @@ -244,7 +245,7 @@ public final class Player { LifeState invulnerable = new LifeState(newLives, LifeState.State.INVULNERABLE); LifeState vulnerable = new LifeState(newLives, LifeState.State.VULNERABLE); - nextLifeState = nextLifeState.concat(Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS,invulnerable)); + nextLifeState = nextLifeState.concat(Sq.repeat(Ticks.PLAYER_INVULNERABLE_TICKS, invulnerable)); nextLifeState = nextLifeState.concat(Sq.constant(vulnerable)); } @@ -327,4 +328,5 @@ public final class Player { public Bomb newBomb() { return new Bomb(id, position().containingCell(), Ticks.BOMB_FUSE_TICKS, bombRange); } + } diff --git a/test/ch/epfl/xblast/namecheck/NameCheck03.java b/test/ch/epfl/xblast/namecheck/NameCheck03.java index 9cad907..fc2a4b5 100644 --- a/test/ch/epfl/xblast/namecheck/NameCheck03.java +++ b/test/ch/epfl/xblast/namecheck/NameCheck03.java @@ -1,16 +1,12 @@ package ch.epfl.xblast.namecheck; -import java.util.List; - import ch.epfl.cs108.Sq; -import ch.epfl.xblast.ArgumentChecker; -import ch.epfl.xblast.Cell; -import ch.epfl.xblast.Direction; -import ch.epfl.xblast.PlayerID; -import ch.epfl.xblast.SubCell; +import ch.epfl.xblast.*; import ch.epfl.xblast.server.Bomb; import ch.epfl.xblast.server.Player; +import java.util.List; + /** * Classe abstraite utilisant tous les éléments de l'étape 3, pour essayer de * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est @@ -18,8 +14,8 @@ import ch.epfl.xblast.server.Player; * * @author EPFL */ - abstract class NameCheck03 { + void checkArgumentChecker() { ArgumentChecker.requireNonNegative(10); } @@ -89,4 +85,5 @@ abstract class NameCheck03 { List>> x = b.explosion(); System.out.println(String.valueOf(t) + x); } + } -- cgit v1.2.3