Zwischen-Commit 02 (nextGeneration+ isAlive fertig)
This commit is contained in:
parent
68fc76793f
commit
f45ef43a78
@ -46,8 +46,7 @@ public class Life implements ILife {
|
||||
|
||||
@Override
|
||||
public boolean isAlive(int x, int y) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return grid[x][y];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,9 +56,40 @@ public class Life implements ILife {
|
||||
|
||||
for(int y = 0; y < GRIDSIZE; y++){
|
||||
for(int x = 0; x < GRIDSIZE; x++){
|
||||
|
||||
int neighborCount = countNeigbours(x, y);
|
||||
if(isAlive(x, y)){
|
||||
if(neighborCount == 2 || neighborCount == 3){
|
||||
nextLife.setAlive(x, y);
|
||||
}
|
||||
}else{
|
||||
if(neighborCount == 3){
|
||||
nextLife.setAlive(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ public class LifeTest {
|
||||
|
||||
@Test
|
||||
public void destroyLonelyCell() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user