aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimothée Floure2016-03-12 14:49:54 +0100
committerTimothée Floure2016-03-12 14:49:54 +0100
commita7fc716ae4123d21254d041797fe114fc44a88e3 (patch)
treeb23d77040304600a99bc19c2ea3f4e38936c8e3c /src
parentb73b2050d345e0ee47fd38952047bdf9d36365d3 (diff)
downloadxblast-a7fc716ae4123d21254d041797fe114fc44a88e3.tar.gz
Fill the Time & Ticks interfaces + the Block & Bonus enums as requested
in the 4th part
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/Time.java15
-rw-r--r--src/ch/epfl/xblast/server/Block.java20
-rw-r--r--src/ch/epfl/xblast/server/Bonus.java12
-rw-r--r--src/ch/epfl/xblast/server/Ticks.java16
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 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3public interface Time { 3public interface Time {
4 /**
5 * Number of seconds per minute.
6 */
4 int S_PER_MIN = 60; 7 int S_PER_MIN = 60;
8
9 /**
10 * Number of milliseconds per second.
11 */
5 int MS_PER_S = 1000; 12 int MS_PER_S = 1000;
13
14 /**
15 * Number of microseconds per second.
16 */
6 int US_PER_S = 1000*MS_PER_S; 17 int US_PER_S = 1000*MS_PER_S;
18
19 /**
20 * Number of nanoseconds per second.
21 */
7 int NS_PER_S = 1000*US_PER_S; 22 int NS_PER_S = 1000*US_PER_S;
8} 23}
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 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3import java.util.NoSuchElementException;
4
3/** 5/**
4 * A Block. 6 * A Block.
5 * 7 *
@@ -29,12 +31,12 @@ public enum Block {
29 CRUMBLING_WALL, 31 CRUMBLING_WALL,
30 32
31 /** 33 /**
32 * 34 * Bonus increasing the maximun number of bombs.
33 */ 35 */
34 BONUS_BOMB(Bonus.INC_BOMB), 36 BONUS_BOMB(Bonus.INC_BOMB),
35 37
36 /** 38 /**
37 * 39 * Nomus increasing the range of the bombs.
38 */ 40 */
39 BONUS_RANGE(Bonus.INC_RANGE); 41 BONUS_RANGE(Bonus.INC_RANGE);
40 42
@@ -51,7 +53,7 @@ public enum Block {
51 } 53 }
52 54
53 /** 55 /**
54 * Default builder, used by the ither blocks 56 * Default builder, used by the non-bonus blocks
55 */ 57 */
56 private Block() { 58 private Block() {
57 this.maybeAssociatedBonus = null; 59 this.maybeAssociatedBonus = null;
@@ -85,17 +87,25 @@ public enum Block {
85 } 87 }
86 88
87 /** 89 /**
90 * Returns T(this block is a bonus)
88 * 91 *
92 * @return T(this block is a bonus)
89 */ 93 */
90 public boolean isBonus() { 94 public boolean isBonus() {
91 return false; 95 return this == BONUS_BOMB || this == BONUS_RANGE;
92 } 96 }
93 97
94 /** 98 /**
99 * Return the bonus associated with the block.
95 * 100 *
101 * @throws NoSuchElementException if there is no such bonus.
102 * @return the bonus associated with the block.
96 */ 103 */
97 public Bonus associatedBonus() { 104 public Bonus associatedBonus() {
98 return null; 105 if (this.maybeAssociatedBonus == null) {
106 throw new NoSuchElementException();
107 }
108 return this.maybeAssociatedBonus;
99 } 109 }
100 110
101} 111}
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;
4 * @author TimothéE FLOURE (257420) 4 * @author TimothéE FLOURE (257420)
5 */ 5 */
6public enum Bonus { 6public enum Bonus {
7
8 /**
9 * Increase the maximum number of bombs used simultaneously.
10 */
7 INC_BOMB { 11 INC_BOMB {
8 @Override 12 @Override
9 public Player applyTo(Player player) { return null; } 13 public Player applyTo(Player player) { return null; }
10 }, 14 },
11 15
16 /**
17 * Increase the range of the bombs.
18 */
12 INC_RANGE { 19 INC_RANGE {
13 @Override 20 @Override
14 public Player applyTo(Player player) { return null; } 21 public Player applyTo(Player player) { return null; }
15 }; 22 };
16 23
24 /**
25 * Apply the bonus to the given player.
26 *
27 * @param player receiving the bonus
28 */
17 abstract public Player applyTo(Player player); 29 abstract public Player applyTo(Player player);
18} 30}
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 {
40 */ 40 */
41 int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS; 41 int BONUS_DISAPPEARING_TICKS = EXPLOSION_TICKS;
42 42
43 /**
44 * Number of ticks per second.
45 */
43 int TICKS_PER_SECOND = 20; 46 int TICKS_PER_SECOND = 20;
44 47
48 /**
49 * Dureation of a tick (in nanoseconds).
50 */
45 int TICK_NANOSECOND_DURATION = TICKS_PER_SECOND / Time.NS_PER_S; 51 int TICK_NANOSECOND_DURATION = TICKS_PER_SECOND / Time.NS_PER_S;
46 52
47 int TOTAL_TICKS = 2 * Time.S_PER_MIN * TICKS_PER_SECOND; 53 /**
54 * Duration of a game (in seconds).
55 */
56 int GAME_DURATION = 2;
57
58 /**
59 * Total number of ticks during a game.
60 */
61 int TOTAL_TICKS = GAME_DURATION * TICKS_PER_SECOND;
48} 62}