Exemplo n.º 1
0
        public Bitmap Draw(CELL_STATE state)
        {
            if (state == CELL_STATE.Alive)
            {
                for (int y = 0; y < Size - 1; y++)
                {
                    for (int x = 0; x < Size - 1; y++)
                    {
                        bitmap.SetPixel(x, y, Color.Green);
                    }
                }
            }
            if (state == CELL_STATE.Dead)
            {
                for (int y = 0; y < Size - 1; y++)
                {
                    for (int x = 0; x < Size - 1; y++)
                    {
                        bitmap.SetPixel(x, y, Color.White);
                    }
                }
            }

            return(bitmap);
        }
Exemplo n.º 2
0
        // Check for amount of neighbours
        private int CellHasNeighbours(Cell[,] grid, int x, int y)
        {
            int        neighboursCount = 0;
            CELL_STATE state           = CELL_STATE.Alive;

            // Top neighbours; we don't check these for cells on the top row.
            if (y != 0)
            {
                if (x != 0 && grid[x - 1, y - 1].State == state)
                {
                    neighboursCount++;                                                           // Top-left
                }
                if (grid[x, y - 1].State == state)
                {
                    neighboursCount++;                                                           // Top-center
                }
                if (x != grid.GetLength(0) - 1 && grid[x + 1, y - 1].State == state)
                {
                    neighboursCount++;                                                                    // Top-right
                }
            }

            // Left-right neighbours; we don't check for the cells on the very first or last index in a row.

            if (x != 0 && grid[x - 1, y].State == state)
            {
                neighboursCount++;                                          // Left
            }
            if (x != grid.GetLength(0) - 1 && grid[x + 1, y].State == state)
            {
                neighboursCount++;                                                              // Right
            }
            // Bottom neighbours; not checking for cells on the last row.
            if (y != grid.GetLength(1) - 1)
            {
                if (x != 0 && grid[x - 1, y + 1].State == state)
                {
                    neighboursCount++;                                                           // Bottom-left
                }
                if (grid[x, y + 1].State == state)
                {
                    neighboursCount++;                                                           // Bottom-center
                }
                if (x != grid.GetLength(0) - 1 && grid[x + 1, y + 1].State == state)
                {
                    neighboursCount++;                                                                    // Bottom-right
                }
            }

            return(neighboursCount);
        }
Exemplo n.º 3
0
 public Cell(CELL_STATE state)
 {
     State = state;
 }
Exemplo n.º 4
0
 public Cell()
 {
     State = CELL_STATE.Empty;
 }