Implementierung nukeAll() + kleinere random Refactorings
This commit is contained in:
parent
092fb1dc01
commit
ecf0483fb1
Binary file not shown.
@ -27,8 +27,11 @@ public class Life implements ILife {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void nukeAll() {
|
public void nukeAll() {
|
||||||
// TODO Auto-generated method stub
|
for (int y = 0; y < grid.length; y++) {
|
||||||
|
for (int x = 0; x < grid[y].length; x++) {
|
||||||
|
grid[x][y] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,17 +55,14 @@ public class Life implements ILife {
|
|||||||
|
|
||||||
for (int y = 0; y < grid.length; y++) {
|
for (int y = 0; y < grid.length; y++) {
|
||||||
for (int x = 0; x < grid[y].length; x++) {
|
for (int x = 0; x < grid[y].length; x++) {
|
||||||
|
int aliveNeighbours = countAliveNeighbours(x, y); // Nur einmal berechnen
|
||||||
|
|
||||||
// Dieser Schritt wäre nun noch ein mögliches Refactoring, um die Fallunterscheidungen zwischen keepAlive und
|
if (isAlive(x, y) && (aliveNeighbours == 2 || aliveNeighbours == 3)) {
|
||||||
// setAlive nochmal deutlicher zu machen, ändert aber eigentlich (soweit ich es sehe) nichts am Codeverhalten.
|
|
||||||
// mMn Ansichtssache, ob das nun redundanter Code ist oder tatsächlich das Verständnis bedeutend verbessert.
|
|
||||||
|
|
||||||
if (isAlive(x, y) && (countAliveNeighbours(x, y) == 3 || countAliveNeighbours(x, y) == 2)) {
|
|
||||||
next.setAlive(x, y);
|
next.setAlive(x, y);
|
||||||
} else if (!isAlive(x, y) && countAliveNeighbours(x, y) == 3) {
|
} else if (!isAlive(x, y) && aliveNeighbours == 3) {
|
||||||
next.setAlive(x, y);
|
next.setAlive(x, y);
|
||||||
} else {
|
} else {
|
||||||
next.setDead(x, y); // das hier ist mMn im Grunde ja auch redundant, da eben die Zellen standardmäßig tot initialisiert werden
|
next.setDead(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user