diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/Cell.java | 81 | ||||
-rw-r--r-- | src/ch/epfl/xblast/Direction.java | 38 | ||||
-rw-r--r-- | src/ch/epfl/xblast/Lists.java | 42 | ||||
-rw-r--r-- | src/ch/epfl/xblast/SubCell.java | 71 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Block.java | 26 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Board.java | 93 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Bomb.java | 52 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/GameState.java | 161 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/Player.java | 464 | ||||
-rw-r--r-- | src/ch/epfl/xblast/server/debug/GameStatePrinter.java | 64 |
10 files changed, 541 insertions, 551 deletions
diff --git a/src/ch/epfl/xblast/Cell.java b/src/ch/epfl/xblast/Cell.java index ecad75b..16632cc 100644 --- a/src/ch/epfl/xblast/Cell.java +++ b/src/ch/epfl/xblast/Cell.java | |||
@@ -36,6 +36,32 @@ public final class Cell { | |||
36 | * The list of the board's Cell-s, spiral-ordered. | 36 | * The list of the board's Cell-s, spiral-ordered. |
37 | */ | 37 | */ |
38 | public static final List<Cell> SPIRAL_ORDER = Collections.unmodifiableList(spiralOrder()); | 38 | public static final List<Cell> SPIRAL_ORDER = Collections.unmodifiableList(spiralOrder()); |
39 | /** | ||
40 | * The coordinates of the Cell. | ||
41 | */ | ||
42 | private final int x, y; | ||
43 | |||
44 | /** | ||
45 | * Instantiates a new Cell with the given coordinates. | ||
46 | * | ||
47 | * @param x the x-coordinate | ||
48 | * @param y the y-coordinate | ||
49 | */ | ||
50 | public Cell(int x, int y) { | ||
51 | this.x = normalize(COLUMNS, x); | ||
52 | this.y = normalize(ROWS, y); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Normalizes the given number (using the integer floor modulus). | ||
57 | * | ||
58 | * @param max the maximum (the divisor) | ||
59 | * @param n the number to normalize (the dividend) | ||
60 | * @return the normalized value | ||
61 | */ | ||
62 | static int normalize(int max, int n) { | ||
63 | return Math.floorMod(n, max); | ||
64 | } | ||
39 | 65 | ||
40 | /** | 66 | /** |
41 | * Builds a major-ordered list of Cell-s. | 67 | * Builds a major-ordered list of Cell-s. |
@@ -97,33 +123,6 @@ public final class Cell { | |||
97 | } | 123 | } |
98 | 124 | ||
99 | /** | 125 | /** |
100 | * Normalizes the given number (using the integer floor modulus). | ||
101 | * | ||
102 | * @param max the maximum (the divisor) | ||
103 | * @param n the number to normalize (the dividend) | ||
104 | * @return the normalized value | ||
105 | */ | ||
106 | static int normalize(int max, int n) { | ||
107 | return Math.floorMod(n, max); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * The coordinates of the Cell. | ||
112 | */ | ||
113 | private final int x, y; | ||
114 | |||
115 | /** | ||
116 | * Instantiates a new Cell with the given coordinates. | ||
117 | * | ||
118 | * @param x the x-coordinate | ||
119 | * @param y the y-coordinate | ||
120 | */ | ||
121 | public Cell(int x, int y) { | ||
122 | this.x = normalize(COLUMNS, x); | ||
123 | this.y = normalize(ROWS, y); | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * Returns the normalized x-coordinate of the Cell. | 126 | * Returns the normalized x-coordinate of the Cell. |
128 | * | 127 | * |
129 | * @return the x-coordinate | 128 | * @return the x-coordinate |
@@ -142,15 +141,6 @@ public final class Cell { | |||
142 | } | 141 | } |
143 | 142 | ||
144 | /** | 143 | /** |
145 | * Returns the index of the Cell (major ordered). | ||
146 | * | ||
147 | * @return the index of the Cell | ||
148 | */ | ||
149 | public int rowMajorIndex() { | ||
150 | return this.y * COLUMNS + this.x; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * Returns the neighboring Cell at the given Direction. | 144 | * Returns the neighboring Cell at the given Direction. |
155 | * | 145 | * |
156 | * @param dir the Direction | 146 | * @param dir the Direction |
@@ -161,6 +151,16 @@ public final class Cell { | |||
161 | } | 151 | } |
162 | 152 | ||
163 | /** | 153 | /** |
154 | * Returns the hash code for this Cell, given by its row-major index. | ||
155 | * | ||
156 | * @return the hash code | ||
157 | */ | ||
158 | @Override | ||
159 | public int hashCode() { | ||
160 | return this.rowMajorIndex(); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * Returns T(the given Object is equal to this Cell (have the same coordinates)). | 164 | * Returns T(the given Object is equal to this Cell (have the same coordinates)). |
165 | * | 165 | * |
166 | * @param that the Object to compare against | 166 | * @param that the Object to compare against |
@@ -175,13 +175,12 @@ public final class Cell { | |||
175 | } | 175 | } |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Returns the hash code for this Cell, given by its row-major index. | 178 | * Returns the index of the Cell (major ordered). |
179 | * | 179 | * |
180 | * @return the hash code | 180 | * @return the index of the Cell |
181 | */ | 181 | */ |
182 | @Override | 182 | public int rowMajorIndex() { |
183 | public int hashCode() { | 183 | return this.y * COLUMNS + this.x; |
184 | return this.rowMajorIndex(); | ||
185 | } | 184 | } |
186 | 185 | ||
187 | /** | 186 | /** |
diff --git a/src/ch/epfl/xblast/Direction.java b/src/ch/epfl/xblast/Direction.java index e2df042..5f5df33 100644 --- a/src/ch/epfl/xblast/Direction.java +++ b/src/ch/epfl/xblast/Direction.java | |||
@@ -29,6 +29,25 @@ public enum Direction { | |||
29 | W; | 29 | W; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * T(the Direction is horizontal to the screen (East or West)). | ||
33 | * | ||
34 | * @return T(the Direction is horizontal to the screen) | ||
35 | */ | ||
36 | public boolean isHorizontal() { | ||
37 | return this == E || this == W; | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * T(the current and given Directions are parallel (identical or opposite)). | ||
42 | * | ||
43 | * @param that a Direction to compare | ||
44 | * @return T(the current and given Directions are parallel) | ||
45 | */ | ||
46 | public boolean isParallelTo(Direction that) { | ||
47 | return that == this || that == this.opposite(); | ||
48 | } | ||
49 | |||
50 | /** | ||
32 | * Returns the opposite Direction. | 51 | * Returns the opposite Direction. |
33 | * | 52 | * |
34 | * @return the opposite Direction | 53 | * @return the opposite Direction |
@@ -49,25 +68,6 @@ public enum Direction { | |||
49 | } | 68 | } |
50 | 69 | ||
51 | /** | 70 | /** |
52 | * T(the Direction is horizontal to the screen (East or West)). | ||
53 | * | ||
54 | * @return T(the Direction is horizontal to the screen) | ||
55 | */ | ||
56 | public boolean isHorizontal() { | ||
57 | return this == E || this == W; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * T(the current and given Directions are parallel (identical or opposite)). | ||
62 | * | ||
63 | * @param that a Direction to compare | ||
64 | * @return T(the current and given Directions are parallel) | ||
65 | */ | ||
66 | public boolean isParallelTo(Direction that) { | ||
67 | return that == this || that == this.opposite(); | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * T(the current and given Directions are perpendicular). | 71 | * T(the current and given Directions are perpendicular). |
72 | * | 72 | * |
73 | * @param that a Direction to compare | 73 | * @param that a Direction to compare |
diff --git a/src/ch/epfl/xblast/Lists.java b/src/ch/epfl/xblast/Lists.java index 1f2e1c7..d599776 100644 --- a/src/ch/epfl/xblast/Lists.java +++ b/src/ch/epfl/xblast/Lists.java | |||
@@ -13,19 +13,6 @@ import java.util.stream.Stream; | |||
13 | public final class Lists { | 13 | public final class Lists { |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * Returns a reversed copy of the given list, leaving the original one unmodified. | ||
17 | * | ||
18 | * @param l the list to reverse | ||
19 | * @param <T> the type of the list's elements | ||
20 | * @return a reversed copy of the list. | ||
21 | */ | ||
22 | private static <T> List<T> reversed(List<T> l) { | ||
23 | List<T> r = new ArrayList<>(l); | ||
24 | Collections.reverse(r); | ||
25 | return r; | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Returns a symmetric version of the list, without repeating the last element of the input list. | 16 | * Returns a symmetric version of the list, without repeating the last element of the input list. |
30 | * For instance, mirrored([kay]) will return [kayak]. | 17 | * For instance, mirrored([kay]) will return [kayak]. |
31 | * | 18 | * |
@@ -43,17 +30,15 @@ public final class Lists { | |||
43 | } | 30 | } |
44 | 31 | ||
45 | /** | 32 | /** |
46 | * Returns a copy of the given list with element e inserted at index i. | 33 | * Returns a reversed copy of the given list, leaving the original one unmodified. |
47 | * | 34 | * |
48 | * @param l the list | 35 | * @param l the list to reverse |
49 | * @param i the insertion index | ||
50 | * @param e the element to insert | ||
51 | * @param <T> the type of the list's elements | 36 | * @param <T> the type of the list's elements |
52 | * @return a copy of the list with the element inserted | 37 |