A working Version 2 of the GameOfLifeAssignment by Marie Trexler

This commit is contained in:
Marie Trexler 2021-12-23 09:40:41 +01:00
parent 7c967ddab4
commit 067aced45b

View File

@ -107,6 +107,7 @@ public class Life implements ILife {
public int countNeighbor(int x, int y) {
int counter=0;
//counts top row
if(y-1 >=0){
for(int i =x-1; i<= x+1;i++){
if(i>=0 && i< gameWorld[y-1].length()){
@ -116,6 +117,7 @@ public class Life implements ILife {
}
}
}
//counts bottom row
if(y+1 <gameWorld.length){
for(int i =x-1; i<= x+1;i++){
if(i>=0 && i< gameWorld[y+1].length()){
@ -125,6 +127,7 @@ public class Life implements ILife {
}
}
}
//counts sides
if(x-1>=0){
if(isAlive(x-1,y)){
counter++;