From 3b8c85a5f483c856b34c7026f48abd4f355b67d7 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 15 Mar 2016 13:57:11 +0100 Subject: Code clean up and reformatting --- src/ch/epfl/xblast/ArgumentChecker.java | 5 +-- src/ch/epfl/xblast/Time.java | 12 +++++- src/ch/epfl/xblast/server/Block.java | 14 +++--- src/ch/epfl/xblast/server/Bonus.java | 24 ++++++++--- src/ch/epfl/xblast/server/GameState.java | 74 ++++++++++++++++++-------------- src/ch/epfl/xblast/server/Ticks.java | 3 +- 6 files changed, 78 insertions(+), 54 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/xblast/ArgumentChecker.java b/src/ch/epfl/xblast/ArgumentChecker.java index 311807e..589c197 100644 --- a/src/ch/epfl/xblast/ArgumentChecker.java +++ b/src/ch/epfl/xblast/ArgumentChecker.java @@ -16,11 +16,10 @@ public final class ArgumentChecker { * @throws IllegalArgumentException if the value is inferior to 0 */ public static int requireNonNegative(int value) { - if (value >= 0) { + if (value >= 0) return value; - } else { + else throw new IllegalArgumentException(); - } } } diff --git a/src/ch/epfl/xblast/Time.java b/src/ch/epfl/xblast/Time.java index d39c3e3..7c84257 100644 --- a/src/ch/epfl/xblast/Time.java +++ b/src/ch/epfl/xblast/Time.java @@ -1,6 +1,13 @@ package ch.epfl.xblast; +/** + * Time unit constants. + * + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public interface Time { + /** * Number of seconds per minute. */ @@ -14,10 +21,11 @@ public interface Time { /** * Number of microseconds per second. */ - int US_PER_S = 1000*MS_PER_S; + int US_PER_S = 1000 * MS_PER_S; /** * Number of nanoseconds per second. */ - int NS_PER_S = 1000*US_PER_S; + int NS_PER_S = 1000 * US_PER_S; + } diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java index fff3819..c90a469 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java @@ -31,12 +31,12 @@ public enum Block { CRUMBLING_WALL, /** - * Bonus increasing the maximun number of bombs. + * Bonus increasing the maximum number of bombs. */ BONUS_BOMB(Bonus.INC_BOMB), /** - * Nomus increasing the range of the bombs. + * Bonus increasing the range of the bombs. */ BONUS_RANGE(Bonus.INC_RANGE); @@ -87,7 +87,7 @@ public enum Block { } /** - * Returns T(this block is a bonus) + * Returns T(this block is a bonus). * * @return T(this block is a bonus) */ @@ -96,15 +96,13 @@ public enum Block { } /** - * Return the bonus associated with the block. + * Returns the bonus associated with the block. * - * @throws NoSuchElementException if there is no such bonus. * @return the bonus associated with the block. + * @throws NoSuchElementException if there is no such bonus. */ public Bonus associatedBonus() { - if (this.maybeAssociatedBonus == null) { - throw new NoSuchElementException(); - } + if (this.maybeAssociatedBonus == null) throw new NoSuchElementException(); return this.maybeAssociatedBonus; } diff --git a/src/ch/epfl/xblast/server/Bonus.java b/src/ch/epfl/xblast/server/Bonus.java index 81ae7dd..09a2248 100644 --- a/src/ch/epfl/xblast/server/Bonus.java +++ b/src/ch/epfl/xblast/server/Bonus.java @@ -1,24 +1,33 @@ package ch.epfl.xblast.server; /** - * @author TimothéE FLOURE (257420) + * Bonuses. + * + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) */ public enum Bonus { /** - * Increase the maximum number of bombs used simultaneously. + * Increases the maximum number of bombs used simultaneously. */ INC_BOMB { - @Override - public Player applyTo(Player player) { return null; } + @Override + public Player applyTo(Player player) { + // TODO + return null; + } }, /** - * Increase the range of the bombs. + * Increases the range of the bombs. */ INC_RANGE { - @Override - public Player applyTo(Player player) { return null; } + @Override + public Player applyTo(Player player) { + // TODO + return null; + } }; /** @@ -27,4 +36,5 @@ public enum Bonus { * @param player receiving the bonus */ abstract public Player applyTo(Player player); + } diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 3bd1961..e7e6ca7 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -1,17 +1,22 @@ package ch.epfl.xblast.server; +import ch.epfl.cs108.Sq; +import ch.epfl.xblast.ArgumentChecker; +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.PlayerID; + +import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.Objects; -import java.util.ArrayList; import java.util.Optional; -import ch.epfl.xblast.*; -import ch.epfl.cs108.Sq; +import java.util.stream.Collectors; /** + * GameState representing the current game state. + * + * @author Pacien TRAN-GIRARD (261948) * @author Timothée FLOURE (257420) */ - public final class GameState { private final int ticks; @@ -24,8 +29,8 @@ public final class GameState { /** * Compute the next state of a blast. * - * @param blasts0 existing particles - * @param board0 the game's board + * @param blasts0 existing particles + * @param board0 the game's board * @param explosions0 active explosions * @return the position of the explosion's particles for the next state. */ @@ -43,16 +48,16 @@ public final class GameState { } /** - * Instanciates a new GameState. + * Instantiates a new GameState. * - * @param ticks thie tick corresponding to the state - * @param board the game's board - * @param players list of the players - * @param bombs list of the bombs + * @param ticks the tick corresponding to the state + * @param board the game's board + * @param players list of the players + * @param bombs list of the bombs * @param explosions list of the explosions - * @param blasts - * @throws IllegalArguementException if ticks is negative or players does not contains 4 players. - * @throws NullPointerException if any element except ticks is null. + * @param blasts list of particle blasts + * @throws IllegalArgumentException if ticks is negative or players does not contains 4 players. + * @throws NullPointerException if any element except ticks is null. */ public GameState(int ticks, Board board, List players, List bombs, List>> explosions, List> blasts) { this.ticks = ArgumentChecker.requireNonNegative(ticks); @@ -68,19 +73,19 @@ public final class GameState { } /** - * Instanciates a new (clean) GameState. + * Instantiates a new (clean) GameState. * - * @param board the board + * @param board the board * @param players list of the players */ public GameState(Board board, List players) { this(0, - board, - players, - new ArrayList(), - new ArrayList>>(), - new ArrayList>() - ); + board, + players, + new ArrayList(), + new ArrayList>>(), + new ArrayList>() + ); } @@ -88,18 +93,20 @@ public final class GameState { * @return the tick related to the state. */ public int ticks() { - return ticks; + return this.ticks; } /** - * Returns T(the game is over) + * Returns T(the game is over). * - * @return true if all the players are dead or if the game reachead the time limit + * @return true if all the players are dead or if the game reached the time limit */ public boolean isGameOver() { int alivePlayerCount = 0; - for (Player player : players) { - if (player.isAlive()) {alivePlayerCount += 1;} + for (Player player : this.players) { + if (player.isAlive()) { + alivePlayerCount += 1; + } } if (alivePlayerCount == 0 || this.ticks >= Ticks.TOTAL_TICKS) { return true; @@ -111,7 +118,7 @@ public final class GameState { /** * Return the remaining time. * - * @return the ramaining game time (in seconds) + * @return the remaining game time (in seconds) */ public double remainingTime() { return (double) (Ticks.TOTAL_TICKS - this.ticks) / Ticks.TICKS_PER_SECOND; @@ -120,11 +127,11 @@ public final class GameState { /** * Returns the winner of the game. * - * @return the ID of the player who winned the game. + * @return the ID of the player who won the game. */ public Optional winner() { - if (players.size() == 1 && this.ticks < Ticks.TOTAL_TICKS) { - PlayerID winnerId = players.get(0).id(); + if (this.players.size() == 1 && this.ticks < Ticks.TOTAL_TICKS) { + PlayerID winnerId = this.players.get(0).id(); return Optional.of(winnerId); } else { return Optional.empty(); @@ -153,7 +160,7 @@ public final class GameState { public List alivePlayers() { List alivePlayers = new ArrayList<>(); - for (Player player : players) { + for (Player player : this.players) { if (player.isAlive()) { alivePlayers.add(player); } @@ -161,4 +168,5 @@ public final class GameState { return alivePlayers; } + } diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index d27d20c..3517491 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -46,7 +46,7 @@ public interface Ticks { int TICKS_PER_SECOND = 20; /** - * Dureation of a tick (in nanoseconds). + * Duration of a tick (in nanoseconds). */ int TICK_NANOSECOND_DURATION = TICKS_PER_SECOND / Time.NS_PER_S; @@ -59,4 +59,5 @@ public interface Ticks { * Total number of ticks during a game. */ int TOTAL_TICKS = GAME_DURATION * TICKS_PER_SECOND; + } -- cgit v1.2.3