Loop through a 2d array of objects
I was wondering if anyone can tell me a statement to iterate through a 2d array of objects called "animalsAndGrass".
While it is iterating through it I want to be able to output the open locations i.e. the locations in the 2d array not holding any objects.
For example i know i can iterate through the array like so..
for (int i = 0; i < ROWS; i++)
for (int j = 0; j < COLS; j++)
Would I be better to output and store the open locations to another 2d array? or what should I do?
I'm so confused
this is for my dissertation I need to loop through the array and..
If it is an empty cell in the grid (2d array)
and 3 or more neighbouring cells are a grass object then create a grass object and place it in the empty space
Thank you very much for your help.
Re: Loop through a 2d array of objects
If you know how to iterate through the array then it is a simple matter of checking if the cell has an object in it or not. A simple if statement checking the cell (based on i and j) and outputting something like "has object" and "no object" would be a good place to start and go from there.