コード例 #1
0
ファイル: Grid.cs プロジェクト: Telope/BurningSimulator
        // This method handles the logic for the simulation from start to finish
        // Detailed in-line comments outline the sections of this method
        public void Burn()
        {
            // Instantiate cells
            cells = new Cell[numColumns, numRows];
            for (int i = 0; i < numColumns; i++)
            {
                for (int j = 0; j < numRows; j++)
                {
                    cells[i, j] = new Cell(i, j, this);
                }
            }

            // Reset grid and burn statistics and print the starting grid
            fireDuration = 0;
            biggestFire  = 0;
            this.Reset();
            CentreCell().Ignite();
            Print();

            // Logic for burning the grid

            // As long as there are cells still burning...
            while (burningCells.Any())
            {
                // Update the burn statistics
                fireDuration++;
                if (biggestFire < burningCells.Count)
                {
                    biggestFire = burningCells.Count;
                }

                // Spread the fire to the neighbouring trees of each burning cell
                foreach (Cell cell in burningCells)
                {
                    // cell.timeburned++;
                    cell.SetTimeBurned(cell.GetTimeBurned() + 1);

                    SpreadFire(cell);

                    // If the cell has burned for too long, it will burn out later in this tick
                    if (cell.GetTimeBurned() >= Cell.GetBurnTime())
                    {
                        cellsToDie.Add(cell);
                    }
                }

                // Any burning cells that have burned for too long burn out
                foreach (Cell cell in cellsToDie)
                {
                    cell.Die();
                }
                cellsToDie.Clear();

                // Each tree next to a burning cell has a chance to start burning
                foreach (Cell cell in cellsToBurn)
                {
                    cell.AttemptIgnition(rng);
                }
                cellsToBurn.Clear();

                // Wait for user input. Placing this check after the logic is calculated
                // should marginally increase responsiveness
                Console.ReadKey();

                Print();
            }
        }
コード例 #2
0
ファイル: Grid.cs プロジェクト: Telope/BurningSimulator
 public void RemoveFromBurningCells(Cell cell)
 {
     burningCells.Remove(cell);
 }