private bool InGridBounds(int countRow, int countCol, Cell cell) { return (cell.Row + countRow < Dimension) && (cell.Row + countRow >= 0) && (cell.Column + countCol < Dimension) && (cell.Column + countCol >= 0); }
public void Initialize() { Cells = new Cell[Dimension,Dimension]; for (int i = 0; i < Dimension; i++) { for (int j = 0; j < Dimension; j++) { Cells[i, j] = new Cell(i, j); } } }
private static Brush GetCellColor(Cell cell) { Brush fillPen = Brushes.White; switch (cell.CellState) { case Enums.CellState.Dead: fillPen = Brushes.Black; break; case Enums.CellState.DeadLonely: fillPen = Brushes.Blue; //fillPen = Brushes.Black; break; case Enums.CellState.DeadOvercrowded: fillPen = Brushes.Red; //fillPen = Brushes.Black; break; } return fillPen; }
private int NeighborsCount(Cell cell) { int neighbors = 0; for (int countRow = -1; countRow <= 1; countRow++) { for (int countCol = -1; countCol <= 1; countCol++) { if (InGridBounds(countRow, countCol, cell) && !IsCell(countRow, countCol)) { if (Cells[cell.Row + countRow, cell.Column + countCol].CellState == Enums.CellState.Alive) neighbors++; } } } return neighbors; }