示例#1
0
        private void SwitchCellState()
        {
            //Go through the grid
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    //Check the surrounding cells
                    int neighborCell = _gridService.CountNeighborCells(i, j, rows, cols, _currentCell);

                    //Change cell state from dead to alive
                    if (_currentCell[i, j].Fill == Brushes.Red && neighborCell == 3)
                    {
                        _currentCell[i, j].Fill = Brushes.ForestGreen;
                        //_countAlive++;
                    }

                    //Change cell state from alive to dead
                    else if (_currentCell[i, j].Fill == Brushes.ForestGreen && (neighborCell < 2 || neighborCell > 3))
                    {
                        _currentCell[i, j].Fill = Brushes.Red;
                    }

                    //Doesn't work correctly, need a second variable...
                    else
                    {
                        _currentCell[i, j].Fill = _currentCell[i, j].Fill;
                        if (_currentCell[i, j].Fill == Brushes.ForestGreen)
                        {
                            _countAlive++;
                        }
                    }
                }
            }

            _countTries++;
        }