public class Life implements ILife { public static void main(String[] args) { Life l = new Life(new String[] { " ", " ", " *** ", " ", " " }); l = (Life) l.nextGeneration(); } public Life() { nukeAll(); } public Life(String[] setup) { this(); for (int y = 0; y < setup.length; y++) for (int x = 0; x < setup[y].length(); x++) if (setup[y].charAt(x) != ' ') setAlive(x, y); } @Override public void nukeAll() { // TODO Auto-generated method stub } @Override public void setAlive(int x, int y) { // TODO Auto-generated method stub } @Override public void setDead(int x, int y) { // TODO Auto-generated method stub } @Override public boolean isAlive(int x, int y) { // TODO Auto-generated method stub return false; } @Override public ILife nextGeneration() { Life newLife = new Life(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int neighbors = countAliveNeighbors(x, y); if (isAlive(x, y)) { if (neighbors < 2 || neighbors > 3) { newLife.setDead(x, y); } else { newLife.setAlive(x, y); } } } } return newLife; } private int countAliveNeighbors(int x, int y) { int count = 0; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dx == 0 && dy == 0) continue; // Eigene Zelle ignorieren if (isAlive(x + dx, y + dy)) count++; } } return count; } }