Refactoring (?): isAlive() tatsächliche Überprüfung eingefügt, dazu setAlive() nötig etc.

This commit is contained in:
Susanne 2025-02-15 19:30:24 +01:00
parent 41e60e145b
commit fc7a99931f
3 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,6 @@
public class Life implements ILife {
private boolean[][] grid = new boolean[5][5]; // vorläufig 5x5 Raster
public static void main(String[] args) {
Life l = new Life(new String[] { " ",
@ -32,7 +33,7 @@ public class Life implements ILife {
@Override
public void setAlive(int x, int y) {
// TODO Auto-generated method stub
grid[x][y] = true; // damit Test grün wird, muss Zelle im grid true (alive) werden
}
@Override
@ -43,12 +44,18 @@ public class Life implements ILife {
@Override
public boolean isAlive(int x, int y) {
return true;
// REFACTORING: return nicht mehr einfach auf 'true' setzen, sondern tatsächlich eine Überprüfung ausführen
// Zustand der Zelle an Position (x, y)
return grid[x][y];
// -> grid muss erstellt werden, siehe Zeile 3
}
@Override
public ILife nextGeneration() {
Life next = new Life();
next.setAlive(1,1); // muss jetzt ausgelöst werden, damit Zelle alive wird
return next;
}
}