Hi all,
For my java class I need to make the game of life. So far I have 2 main classes that drive the program (ignoring GUI class for now.)
My main classes:
Cell(x, y) - where x = the x coordinate and y = the y coordinate of the 2D Array. Cell also has an int life = 0 in the constructor stating that it starts dead.
Cell has all get/set functions for x, y, and life variables
ArrayBoard() - which holds a 2D Array of Cells.
To start I loop through the array adding new cells:
//run loop to fill board with Cells with life = 0
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
board[i][j] = new Cell(i,j);
}
}
My problem lies within checking whether the Cell's (at that given point of the loop) life is = 1.
So, I've created a for loop to loop through, but I'm lost as to how to reference that specific cell and its life variable. I know, in the past I've looped through a 1D array and referencing the function by calling something like: board.get(i).getLife();
however, this confuses me as to how to reference the object and its functions in a 2D Array.
Any help would be much appreciated!
Thanks in advance