aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien2016-03-15 14:54:24 +0100
committerPacien2016-03-15 14:54:24 +0100
commitcd660d9d08a3c396afc3a9b7ba0e4b30cab26a54 (patch)
treeb099dbb7ab11c2c18070b2c7a41872a60c678c14
parent5309cf4c441571a94e6c0033765ec43a3dc67ec8 (diff)
parent9ab2568b7519615165fa869c1852b0afbb4950e7 (diff)
downloadxblast-cd660d9d08a3c396afc3a9b7ba0e4b30cab26a54.tar.gz
Merge branch '04_bonus_and_game_state' into 'master'
04 bonus and game state See merge request !4
-rw-r--r--src/ch/epfl/xblast/ArgumentChecker.java5
-rw-r--r--src/ch/epfl/xblast/Lists.java40
-rw-r--r--src/ch/epfl/xblast/Time.java31
-rw-r--r--src/ch/epfl/xblast/server/Block.java53
-rw-r--r--src/ch/epfl/xblast/server/Bonus.java55
-rw-r--r--src/ch/epfl/xblast/server/GameState.java146
-rw-r--r--src/ch/epfl/xblast/server/Ticks.java22
-rw-r--r--src/ch/epfl/xblast/server/debug/GameStatePrinter.java81
-rw-r--r--test/ch/epfl/xblast/ListsTest.java15
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck04.java78
10 files changed, 519 insertions, 7 deletions
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 {
16 * @throws IllegalArgumentException if the value is inferior to 0 16 * @throws IllegalArgumentException if the value is inferior to 0
17 */ 17 */
18 public static int requireNonNegative(int value) { 18 public static int requireNonNegative(int value) {
19 if (value >= 0) { 19 if (value >= 0)
20 return value; 20 return value;
21 } else { 21 else
22 throw new IllegalArgumentException(); 22 throw new IllegalArgumentException();
23 }
24 } 23 }
25 24
26} 25}
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java
index 51e76b0..4ea45c2 100644
--- a/src/ch/epfl/xblast/Lists.java
+++ b/src/ch/epfl/xblast/Lists.java
@@ -1,8 +1,6 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import java.util.ArrayList; 3import java.util.*;
4import java.util.Collections;
5import java.util.List;
6import java.util.stream.Collectors; 4import java.util.stream.Collectors;
7import java.util.stream.Stream; 5import java.util.stream.Stream;
8 6
@@ -44,4 +42,40 @@ public final class Lists {
44 .collect(Collectors.toList()); 42 .collect(Collectors.toList());
45 } 43 }
46 44
45 /**
46 * Returns a copy of the given list with element e inserted at index i.
47 *
48 * @param l the list
49 * @param i the insertion index
50 * @param e the element to insert
51 * @param <T> the type of the list's elements
52 * @return a copy of the list with the element inserted
53 */
54 public static <T> List<T> inserted(List<T> l, int i, T e) {
55 List<T> r = new LinkedList<>(l);
56 r.add(i, e);
57 return r;
58 }
59
60 /**
61 * Returns all the permutations of the elements of the given list
62 *
63 * @param l given list
64 * @param <T> the type of the list's elements
65 * @return a list of all the permutations of the list
66 * @throws IllegalArgumentException if the given list is null
67 */
68 public static <T> List<List<T>> permutations(List<T> l) {
69 if (l == null) throw new IllegalArgumentException();
70 if (l.size() <= 1) return Collections.singletonList(l);
71 if (l.size() == 2) return Arrays.asList(l, Lists.reversed(l));
72
73 List<List<T>> p = new LinkedList<>();
74 for (List<T> sp : Lists.permutations(l.subList(1, l.size())))
75 for (int i = 0; i <= sp.size(); ++i)
76 p.add(Lists.inserted(sp, i, l.get(0)));
77
78 return p;
79 }
80
47} 81}
diff --git a/src/ch/epfl/xblast/Time.java b/src/ch/epfl/xblast/Time.java
new file mode 100644
index 0000000..7c84257
--- /dev/null
+++ b/src/ch/epfl/xblast/Time.java
@@ -0,0 +1,31 @@
1package ch.epfl.xblast;
2
3/**
4 * Time unit constants.
5 *
6 * @author Pacien TRAN-GIRARD (261948)
7 * @author Timothée FLOURE (257420)
8 */
9public interface Time {
10
11 /**
12 * Number of seconds per minute.
13 */
14 int S_PER_MIN = 60;
15
16 /**
17 * Number of milliseconds per second.
18 */
19 int MS_PER_S = 1000;
20
21 /**
22 * Number of microseconds per second.
23 */
24 int US_PER_S = 1000 * MS_PER_S;
25
26 /**
27 * Number of nanoseconds per second.
28 */
29 int NS_PER_S = 1000 * US_PER_S;
30
31}
diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java
index 409f68e..5a139ff 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 *
@@ -26,7 +28,36 @@ public enum Block {
26 /** 28 /**
27 * Crumbling Wall. 29 * Crumbling Wall.
28 */ 30 */
29 CRUMBLING_WALL; 31 CRUMBLING_WALL,
32
33 /**
34 * Bonus increasing the maximum number of bombs.
35 */
36 BONUS_BOMB(Bonus.INC_BOMB),
37
38 /**
39 * Bonus increasing the range of the bombs.
40 */
41 BONUS_RANGE(Bonus.INC_RANGE);
42
43 /**
44 * Corresponding bonus, or null
45 */
46 private Bonus maybeAssociatedBonus;
47
48 /**
49 * Main builder, used by the bonus blocks
50 */
51 Block(Bonus maybeAssociatedBonus) {
52 this.maybeAssociatedBonus = maybeAssociatedBonus;
53 }
54
55 /**
56 * Default builder, used by the non-bonus blocks
57 */
58 Block() {
59 this.maybeAssociatedBonus = null;
60 }
30 61
31 /** 62 /**
32 * Returns T(this block is free). 63 * Returns T(this block is free).
@@ -55,4 +86,24 @@ public enum Block {
55 return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL; 86 return this == INDESTRUCTIBLE_WALL || this == DESTRUCTIBLE_WALL || this == CRUMBLING_WALL;
56 } 87 }
57 88
89 /**
90 * Returns T(this block is a bonus).
91 *
92 * @return T(this block is a bonus)
93 */
94 public boolean isBonus() {
95 return this == BONUS_BOMB || this == BONUS_RANGE;
96 }
97
98 /**
99 * Returns the bonus associated with the block.
100 *
101 * @return the bonus associated with the block.
102 * @throws NoSuchElementException if there is no such bonus.
103 */
104 public Bonus associatedBonus() {
105 if (this.maybeAssociatedBonus == null) throw new NoSuchElementException();
106 return this.maybeAssociatedBonus;
107 }
108
58} 109}
diff --git a/src/ch/epfl/xblast/server/Bonus.java b/src/ch/epfl/xblast/server/Bonus.java
new file mode 100644
index 0000000..80ca8a9
--- /dev/null
+++ b/src/ch/epfl/xblast/server/Bonus.java
@@ -0,0 +1,55 @@
1package ch.epfl.xblast.server;
2
3/**
4 * Bonuses.
5 *
6 * @author Pacien TRAN-GIRARD (261948)
7 * @author Timothée FLOURE (257420)
8 */
9public enum Bonus {
10
11 /**
12 * Increases the maximum number of bombs used simultaneously.
13 */
14 INC_BOMB {
15 @Override
16 public Player applyTo(Player player) {
17 if (player.maxBombs() < BOMBS_LIMIT)
18 return player.withMaxBombs(player.maxBombs() + 1);
19 else
20 return player.withMaxBombs(BOMBS_LIMIT);
21 }
22 },
23
24 /**
25 * Increases the range of the bombs.
26 */
27 INC_RANGE {
28 @Override
29 public Player applyTo(Player player) {
30 if (player.bombRange() < RANGE_LIMIT)
31 return player.withBombRange(player.bombRange() + 1);
32 else
33 return player.withBombRange(RANGE_LIMIT);
34 }
35 };
36
37 /**
38 * Maximum number of bombs.
39 */
40 private final int BOMBS_LIMIT = 9;
41