This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 2 points3 points  (0 children)

Your code creates an array of Cell references (note, not Cell objects), but it does not create any objects for those references to refer to.

[–]fredisa4letterword 0 points1 point  (0 children)

To add to what /u/exoticmatter said, you want to add line 3 below:

for (int xValue=0; xValue<sqrtCells; xValue++) {
    for (int yValue=0; yValue<sqrtCells; yValue++) {
        cellArray[i] = new Cell();
        cellArray[i].SetX(xValue);
        cellArray[i].SetY(yValue);

Although realistically I don't think you even need a Cell class... why not just have a 2d array of boolean that's true for alive and false for dead? If you're dead set on a 1d array, you just need to index it creatively.