diff options
author | Pacien TRAN-GIRARD | 2016-05-10 17:11:13 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-05-10 17:11:13 +0200 |
commit | e19a8b7ac050d1565fdf781b3ab86cda30042e85 (patch) | |
tree | 035329dfff28227f094354d38da3932212d917b1 /src | |
parent | 766114c05bcd0b0388988aaf606e046857e6946a (diff) | |
download | xblast-e19a8b7ac050d1565fdf781b3ab86cda30042e85.tar.gz |
Implement Cell and SubCell natural ordering
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/Cell.java | 13 | ||||
-rw-r--r-- | src/ch/epfl/xblast/SubCell.java | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/ch/epfl/xblast/Cell.java b/src/ch/epfl/xblast/Cell.java index 8214066..6874b54 100644 --- a/src/ch/epfl/xblast/Cell.java +++ b/src/ch/epfl/xblast/Cell.java | |||
@@ -10,7 +10,7 @@ import java.util.List; | |||
10 | * @author Pacien TRAN-GIRARD (261948) | 10 | * @author Pacien TRAN-GIRARD (261948) |
11 | * @author Timothée FLOURE (257420) | 11 | * @author Timothée FLOURE (257420) |
12 | */ | 12 | */ |
13 | public final class Cell { | 13 | public final class Cell implements Comparable<Cell> { |
14 | 14 | ||
15 | /** | 15 | /** |
16 | * The width of the board (number of columns). | 16 | * The width of the board (number of columns). |
@@ -194,4 +194,15 @@ public final class Cell { | |||
194 | return String.format("(%d,%d)", this.x, this.y); | 194 | return String.format("(%d,%d)", this.x, this.y); |
195 | } | 195 | } |
196 | 196 | ||
197 | /** | ||
198 | * Compares two Cells relatively to their row major indexes. | ||
199 | * | ||
200 | * @param cell the other Cell to compare | ||
201 | * @return the comparison result | ||
202 | */ | ||
203 | @Override | ||
204 | public int compareTo(Cell cell) { | ||
205 | return Integer.compare(this.rowMajorIndex(), cell.rowMajorIndex()); | ||
206 | } | ||
207 | |||
197 | } | 208 | } |
diff --git a/src/ch/epfl/xblast/SubCell.java b/src/ch/epfl/xblast/SubCell.java index 4278fab..fd9db0b 100644 --- a/src/ch/epfl/xblast/SubCell.java +++ b/src/ch/epfl/xblast/SubCell.java | |||
@@ -6,7 +6,7 @@ package ch.epfl.xblast; | |||
6 | * @author Pacien TRAN-GIRARD (261948) | 6 | * @author Pacien TRAN-GIRARD (261948) |
7 | * @author Timothée FLOURE (257420) | 7 | * @author Timothée FLOURE (257420) |
8 | */ | 8 | */ |
9 | public final class SubCell { | 9 | public final class SubCell implements Comparable<SubCell> { |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * The number of x-subdivisions of each Cell. | 12 | * The number of x-subdivisions of each Cell. |
@@ -165,4 +165,15 @@ public final class SubCell { | |||
165 | return this.y * SUB_COLUMNS + this.x; | 165 | return this.y * SUB_COLUMNS + this.x; |
166 | } | 166 | } |
167 | 167 | ||
168 | /** | ||
169 | * Compares two SubCells relatively to their row major indexes. | ||
170 | * | ||
171 | * @param subCell the other SubCell to compare | ||
172 | * @return the comparison result | ||
173 | */ | ||
174 | @Override | ||
175 | public int compareTo(SubCell subCell) { | ||
176 | return Integer.compare(this.rowMajorIndex(), subCell.rowMajorIndex()); | ||
177 | } | ||
178 | |||
168 | } | 179 | } |