|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int countNeighbor(int x, int y) { |
|
|
public int countNeighbor(int x, int y) { |
|
|
int counter=0; |
|
|
int counter=0; |
|
|
|
|
|
//counts top row |
|
|
if(y-1 >=0){ |
|
|
if(y-1 >=0){ |
|
|
for(int i =x-1; i<= x+1;i++){ |
|
|
for(int i =x-1; i<= x+1;i++){ |
|
|
if(i>=0 && i< gameWorld[y-1].length()){ |
|
|
if(i>=0 && i< gameWorld[y-1].length()){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//counts bottom row |
|
|
if(y+1 <gameWorld.length){ |
|
|
if(y+1 <gameWorld.length){ |
|
|
for(int i =x-1; i<= x+1;i++){ |
|
|
for(int i =x-1; i<= x+1;i++){ |
|
|
if(i>=0 && i< gameWorld[y+1].length()){ |
|
|
if(i>=0 && i< gameWorld[y+1].length()){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//counts sides |
|
|
if(x-1>=0){ |
|
|
if(x-1>=0){ |
|
|
if(isAlive(x-1,y)){ |
|
|
if(isAlive(x-1,y)){ |
|
|
counter++; |
|
|
counter++; |