Zwischen-Commit 03 (verbesserung countNeighbours+ Test 1 createNewCell grün)

This commit is contained in:
Saskia Doerk 2025-02-15 16:45:25 +01:00
parent f45ef43a78
commit 3bbf66ea1f
2 changed files with 34 additions and 18 deletions

View File

@ -68,28 +68,28 @@ public class Life implements ILife {
}
}
}
return null;
return nextLife;
}
private int countNeigbours(int x, int y){
private int countNeigbours(int x, int y) {
int count = 0;
if(isAlive(x-1, y-1)){
count ++;
}else if(isAlive(x-1, y)){
count ++;
}else if(isAlive(x-1, y+1)){
count++;
}else if(isAlive(x, y-1)){
count++;
}else if(isAlive(x, y+1)){
count++;
}else if(isAlive(x+1, y-1)){
count++;
}else if(isAlive(x+1, y)){
count++;
}else if(isAlive(x+1, y+1)){
count++;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
if (dx == 0 && dy == 0) continue;
int nx = x + dx;
int ny = y + dy;
if (nx >= 0 && nx < GRIDSIZE && ny >= 0 && ny < GRIDSIZE) {
if (isAlive(nx, ny)) {
count++;
}
}
}
}
return count;
}
}

16
test/LifeTestNukeAll.java Normal file
View File

@ -0,0 +1,16 @@
import junit.framework.TestCase;
public class LifeTestNukeAll extends TestCase {
public static void main(String[] args) {
Life l = new Life(new String[] { " ",
" ",
" *** ",
" ",
" " });
l = (Life) l.nextGeneration();
}
public void testNukeAll() {
}
}