aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/Cell.java13
-rw-r--r--src/ch/epfl/xblast/Direction.java32
-rw-r--r--src/ch/epfl/xblast/SubCell.java13
3 files changed, 34 insertions, 24 deletions
diff --git a/src/ch/epfl/xblast/Cell.java b/src/ch/epfl/xblast/Cell.java
index ef5ff60..9a17f6a 100644
--- a/src/ch/epfl/xblast/Cell.java
+++ b/src/ch/epfl/xblast/Cell.java
@@ -156,18 +156,7 @@ public final class Cell {
156 * @return the neighboring Cell 156 * @return the neighboring Cell
157 */ 157 */
158 public Cell neighbor(Direction dir) { 158 public Cell neighbor(Direction dir) {
159 switch (dir) { 159 return new Cell(this.x + dir.xVector(), this.y + dir.yVector());
160 case N:
161 return new Cell(this.x, this.y - 1);
162 case S:
163 return new Cell(this.x, this.y + 1);
164 case E:
165 return new Cell(this.x + 1, this.y);
166 case W:
167 return new Cell(this.x - 1, this.y);
168 default:
169 return null;
170 }
171 } 160 }
172 161
173 /** 162 /**
diff --git a/src/ch/epfl/xblast/Direction.java b/src/ch/epfl/xblast/Direction.java
index cd4822e..e9d5961 100644
--- a/src/ch/epfl/xblast/Direction.java
+++ b/src/ch/epfl/xblast/Direction.java
@@ -66,4 +66,36 @@ public enum Direction {
66 return that == this || that == this.opposite(); 66 return that == this || that == this.opposite();
67 } 67 }
68 68
69 /**
70 * Returns the x-coordinate of the normed vector representation of the Direction.
71 *
72 * @return the x-coordinate
73 */
74 public int xVector() {
75 switch (this) {
76 case W:
77 return -1;
78 case E:
79 return +1;
80 default:
81 return 0;
82 }
83 }
84
85 /**
86 * Returns the x-coordinate of the normed vector representation of the Direction.
87 *
88 * @return the y-coordinate
89 */
90 public int yVector() {
91 switch (this) {
92 case N:
93 return -1;
94 case S:
95 return +1;
96 default:
97 return 0;
98 }
99 }
100
69} 101}
diff --git a/src/ch/epfl/xblast/SubCell.java b/src/ch/epfl/xblast/SubCell.java
index 2731029..b4f9c91 100644
--- a/src/ch/epfl/xblast/SubCell.java
+++ b/src/ch/epfl/xblast/SubCell.java
@@ -109,18 +109,7 @@ public final class SubCell {
109 * @return the neighboring SubCell 109 * @return the neighboring SubCell
110 */ 110 */
111 public SubCell neighbor(Direction dir) { 111 public SubCell neighbor(Direction dir) {
112 switch (dir) { 112 return new SubCell(this.x + dir.xVector(), this.y + dir.yVector());
113 case N:
114 return new SubCell(this.x, this.y - 1);
115 case S:
116 return new SubCell(this.x, this.y + 1);
117 case E:
118 return new SubCell(this.x + 1, this.y);
119 case W:
120 return new SubCell(this.x - 1, this.y);
121 default:
122 return null;
123 }
124 } 113 }
125 114
126 /** 115 /**