コード例 #1
0
        private void BringToLife(GameCell cell)
        {
            int aliveNeighbors = HowManyAliveNeighbors(cell);

            if (aliveNeighbors == 3)
            {
                cell.MarkForLife();
            }
            else
            {
                cell.MarkForDeath();
            }
        }
コード例 #2
0
        private void Executioner(GameCell cell)
        {
            int aliveNeighbors = HowManyAliveNeighbors(cell);

            if (aliveNeighbors > 3 || aliveNeighbors < 2)
            {
                cell.MarkForDeath();
            }
            else
            {
                cell.MarkForLife();
            }
        }
コード例 #3
0
 /**
  * Toggles live/dead of a selected cell
  * Not possible if GameOfLife runs
  */
 public void SelectCell(GameCell cell)
 {
     if (!backgroundWorker.IsBusy)
     {
         if (!cell.Alive)
         {
             cell.IsAlive();
         }
         else
         {
             cell.IsDead();
         }
     }
 }
コード例 #4
0
        private void SetNeighbors(GameCell cell)
        {
            int rowAbove = IndexDown(cell.Row);
            int rowBelow = IndexUp(cell.Row);
            int colRight = IndexUp(cell.Col);
            int colLeft  = IndexDown(cell.Col);

            List <GameCell> neighbors = new List <GameCell>
            {
                FindByRowAndCol(rowAbove, colLeft),
                FindByRowAndCol(rowAbove, cell.Col),
                FindByRowAndCol(rowAbove, colRight),

                FindByRowAndCol(cell.Row, colLeft),
                FindByRowAndCol(cell.Row, colRight),

                FindByRowAndCol(rowBelow, colLeft),
                FindByRowAndCol(rowBelow, cell.Col),
                FindByRowAndCol(rowBelow, colRight)
            };

            cell.Neighbors = neighbors;
        }
コード例 #5
0
 private int HowManyAliveNeighbors(GameCell cell)
 {
     return(cell.Neighbors.Count(neighbor => neighbor.Alive));
 }
コード例 #6
0
 //Add a cell to the population
 public void AddCells(GameCell cell)
 {
     Cells.Add(cell);
 }