From a7fc716ae4123d21254d041797fe114fc44a88e3 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sat, 12 Mar 2016 14:49:54 +0100 Subject: Fill the Time & Ticks interfaces + the Block & Bonus enums as requested in the 4th part --- src/ch/epfl/xblast/Time.java | 15 +++++++++++++++ src/ch/epfl/xblast/server/Block.java | 20 +++++++++++++++----- src/ch/epfl/xblast/server/Bonus.java | 12 ++++++++++++ src/ch/epfl/xblast/server/Ticks.java | 16 +++++++++++++++- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/ch/epfl/xblast/Time.java b/src/ch/epfl/xblast/Time.java index fa18f86..d39c3e3 100644 --- a/src/ch/epfl/xblast/Time.java +++ b/src/ch/epfl/xblast/Time.java @@ -1,8 +1,23 @@ package ch.epfl.xblast; public interface Time { + /** + * Number of seconds per minute. + */ int S_PER_MIN = 60; + + /** + * Number of milliseconds per second. + */ int MS_PER_S = 1000; + + /** + * Number of microseconds per second. + */ int US_PER_S = 1000*MS_PER_S; + + /** + * Number of nanoseconds per second. + */ 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 4903e2b..fff3819 100644 --- a/src/ch/epfl/xblast/server/Block.java +++ b/src/ch/epfl/xblast/server/Block.java @@ -1,5 +1,7 @@ package ch.epfl.xblast.server; +import java.util.NoSuchElementException; + /** * A Block. * @@ -29,12 +31,12 @@ public enum Block { CRUMBLING_WALL, /** - * + * Bonus increasing the maximun number of bombs. */ BONUS_BOMB(Bonus.INC_BOMB), /** - * + * Nomus increasing the range of the bombs. */ BONUS_RANGE(Bonus.INC_RANGE); @@ -51,7 +53,7 @@ public enum Block { } /** - * Default builder, used by the ither blocks + * Default builder, used by the non-bonus blocks */ private Block() { this.maybeAssociatedBonus = null; @@ -85,17 +87,25 @@ public enum Block { } /** + * Returns T(this block is a bonus) * + * @return T(this block is a bonus) */ public boolean isBonus() { - return false; + return this == BONUS_BOMB || this == BONUS_RANGE; } /** + * Return the bonus associated with the block. * + * @throws NoSuchElementException if there is no such bonus. + * @return the bonus associated with the block. */ public Bonus associatedBonus() { - return null; + 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 43be24f..81ae7dd 100644 --- a/src/ch/epfl/xblast/server/Bonus.java +++ b/src/ch/epfl/xblast/server/Bonus.java @@ -4,15 +4,27 @@ package ch.epfl.xblast.server; * @author TimothéE FLOURE (257420) */ public enum Bonus { + + /** + * Increase the maximum number of bombs used simultaneously. + */ INC_BOMB { @Override public Player applyTo(Player player) { return null; } }, + /** + * Increase the range of the bombs. + */ INC_RANGE { @Override public Player applyTo(Player player) { return null; } }; + /** + * Apply the bonus to the given player. + * + * @param player receiving the bonus + */ abstract public Player applyTo(Player player); } diff --git a/src/ch/epfl/xblast/server/Ticks.java b/src/ch/epfl/xblast/server/Ticks.java index fe3f40c..d27d20c 100644 --- a/src/ch/epfl/xblast/server/Ticks.java +++ b/src/ch/epfl/xblast/server/Ticks.java @@ -40,9 +40,23 @@ public interface Ticks { */ int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; + /** + * Number of ticks per second. + */ int TICKS_PER_SECOND = 20; + /** + * Dureation of a tick (in nanoseconds). + */ int TICK_NANOSECOND_DURATION = TICKS_PER_SECOND / Time.NS_PER_S; - int TOTAL_TICKS = 2 * Time.S_PER_MIN * TICKS_PER_SECOND; + /** + * Duration of a game (in seconds). + */ + int GAME_DURATION = 2; + + /** + * Total number of ticks during a game. + */ + int TOTAL_TICKS = GAME_DURATION * TICKS_PER_SECOND; } -- cgit v1.2.3