From 05dc6bb3d944a3edb90f62dfbe8b85b044839ee7 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 15 Mar 2016 15:36:32 +0100 Subject: Implement Cell and SubCell hashCode() methods --- src/ch/epfl/xblast/Cell.java | 2 +- src/ch/epfl/xblast/SubCell.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ch/epfl/xblast/Cell.java b/src/ch/epfl/xblast/Cell.java index 098c19c..a8a5a08 100644 --- a/src/ch/epfl/xblast/Cell.java +++ b/src/ch/epfl/xblast/Cell.java @@ -181,7 +181,7 @@ public final class Cell { */ @Override public int hashCode() { - return 0; // TODO + return this.rowMajorIndex(); } /** diff --git a/src/ch/epfl/xblast/SubCell.java b/src/ch/epfl/xblast/SubCell.java index 3b7fdb1..8a25997 100644 --- a/src/ch/epfl/xblast/SubCell.java +++ b/src/ch/epfl/xblast/SubCell.java @@ -143,7 +143,7 @@ public final class SubCell { */ @Override public int hashCode() { - return 0; // TODO + return this.rowMajorIndex(); } /** @@ -156,4 +156,13 @@ public final class SubCell { return String.format("(%d,%d)", this.x, this.y); } + /** + * Returns the index of the SubCell (major ordered). + * + * @return the index of the SubCell + */ + private int rowMajorIndex() { + return this.y * SUB_COLUMNS + this.x; + } + } -- cgit v1.2.3