// Развитие клеток и сохранение живых 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); }
// Задать условия жизни клеток 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); }
/// <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); }
public void InitCell() { cellType = StatusCell.NonEmpty; }
public void SetRandomTile(int total) { cellType = (StatusCell)Random.Range(0, total) + 1; }
public void SetCell(StatusCell status, int x, int y) { }