Battlefield.Logic.Fields.Field.Explode C# (CSharp) Method

Explode() public method

Handling explosions.
public Explode ( Battlefield.Logic.GameObjects.Cell cell, bool chainEnabled, Battlefield.Logic.GameObjects.CompositeBomb chainedBombs ) : int
cell Battlefield.Logic.GameObjects.Cell Coordinates and eventually value of the cell.
chainEnabled bool Boolean value if chain reaction enabled.
chainedBombs Battlefield.Logic.GameObjects.CompositeBomb Array for holding chained bombs.
return int
        public int Explode(Cell cell, bool chainEnabled, CompositeBomb chainedBombs)
        {
            var fieldRow = cell.Position.Row;
            var fieldCol = cell.Position.Col;

            // by default cell comes with coordinates only - ex. ChainReaction
            if (cell.Value == 0)
            {
                cell.Value = this.Grid[fieldRow, fieldCol].Value;

                // if no bomb  - detonate the cell and exit the method
                if (cell.Value == 0)
                {
                    this.Grid[fieldRow, fieldCol].Value = DetonatedCell;
                    return 0;
                }
            }

            var bomb = new ExplosionStrategy(cell.Value);
            var explosion = this.InvertExplosion ? bomb.GetInvertedExplosion() : bomb.GetExplosion();

            this.InvertExplosion = false;

            var minesExplodedThisRound = 0;

            // bomb explodes
            for (var explosionRow = -BombRadius; explosionRow <= BombRadius; explosionRow++)
            {
                for (var explosionCol = -BombRadius; explosionCol <= BombRadius; explosionCol++)
                {
                    if (Validators.IsInBounds(fieldRow + explosionRow, this.Size) &&
                        Validators.IsInBounds(fieldCol + explosionCol, this.Size))
                    {
                        if (explosion[explosionRow + BombRadius, explosionCol + BombRadius] == DetonationSpot)
                        {
                            if (this.Grid[fieldRow + explosionRow, fieldCol + explosionCol].Value > EmptyCell)
                            {
                                if (chainEnabled)
                                {
                                    var clonedCell = this.Grid[fieldRow + explosionRow, fieldCol + explosionCol].Clone() as Cell;
                                    chainedBombs.Add(clonedCell);
                                    continue;
                                }

                                minesExplodedThisRound++;
                            }

                            this.Grid[fieldRow + explosionRow, fieldCol + explosionCol].Value = DetonatedCell;
                        }
                    }
                }
            }

            return minesExplodedThisRound;
        }