diff --git a/out/production/GameOfLifeAssignment/Life.class b/out/production/GameOfLifeAssignment/Life.class index 8a8ecef..f9fdfd8 100644 Binary files a/out/production/GameOfLifeAssignment/Life.class and b/out/production/GameOfLifeAssignment/Life.class differ diff --git a/src/Life.java b/src/Life.java index 68a4d7f..dada11d 100644 --- a/src/Life.java +++ b/src/Life.java @@ -27,8 +27,11 @@ public class Life implements ILife { @Override 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 @@ -52,17 +55,14 @@ public class Life implements ILife { for (int y = 0; y < grid.length; y++) { 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 - // 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)) { + if (isAlive(x, y) && (aliveNeighbours == 2 || aliveNeighbours == 3)) { next.setAlive(x, y); - } else if (!isAlive(x, y) && countAliveNeighbours(x, y) == 3) { + } else if (!isAlive(x, y) && aliveNeighbours == 3) { next.setAlive(x, y); } 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); } } }