Exemplo n.º 1
0
        public void Tick()
        {
            Cell[,] newCells = new Cell[width, height];
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    newCells[x, y] = new Cell();
                }
            }
                    int neighbourCount;
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    neighbourCount = 0;
                    neighbourCount = CountNeighbours (neighbourCount, x, y);
                    if (cells[x, y].State == 1)
                    {
                        if (neighbourCount < 2)// die
                            newCells[x, y].State = 0;
                        else if (neighbourCount > 3)// die
                            newCells[x, y].State = 0;
                        else if (neighbourCount == 2 || neighbourCount == 3)// live
                            newCells[x, y].State = 1;
                    }
                    else
                    {
                        if (neighbourCount == 3)// live
                            newCells[x, y].State = 1;
                    }

                }
            }
            cells = (Cell[,])newCells.Clone();
        }