예제 #1
0
        // Развитие клеток и сохранение живых
        public bool Develop()
        {
            List <int[]> survived = new List <int[]>();

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    StatusCell currentCell = plane[i, j];
                    // Живые ячейки. Подсчёт количества
                    int        liveNeighbours = CountLiveNeighbours(i, j);
                    StatusCell result         = SetСondition(currentCell, liveNeighbours);
                    // Save result
                    if (result == StatusCell.Live)
                    {
                        survived.Add(new int[] { i, j });
                    }
                }
            }
            // ОЧистить и затем обновить плоскость
            ClearPlane();
            UpdatePlane(survived);
            bool finished = false;

            // Если есть выжившие клетки, то отобразить их
            // на следующем листе плоскости
            if (this.continuesToLive != null)
            {
                finished = this.continuesToLive.Zip(survived, CompareArrays)
                           .All(x => x);
            }
            this.continuesToLive = survived;
            return(finished);
        }
예제 #2
0
        // Задать условия жизни клеток
        internal StatusCell SetСondition(StatusCell currentCell, int liveNeighbours)
        {
            StatusCell status = StatusCell.Dead;

            if ((currentCell == StatusCell.Live && liveNeighbours == 2) || liveNeighbours == 3)
            {
                status = StatusCell.Live;
            }
            return(status);
        }
예제 #3
0
        /// <summary>
        /// Возвращает изображение клетки указанного типа.
        /// </summary>
        /// <param name="cell">Тип клетки.</param>
        /// <returns>Изображение клетки. null - если изображения для данного типа нет.</returns>
        public Bitmap GetBitmap(StatusCell cell)
        {
            switch (cell)
            {
            case StatusCell.Yes:

                return(normalCell);

            case StatusCell.Static:

                return(staticCell);

            case StatusCell.No:

                return(noCell);
            }

            return(null);
        }
예제 #4
0
 public void InitCell()
 {
     cellType = StatusCell.NonEmpty;
 }
예제 #5
0
 public void SetRandomTile(int total)
 {
     cellType = (StatusCell)Random.Range(0, total) + 1;
 }
예제 #6
0
 public void SetCell(StatusCell status, int x, int y)
 {
 }