private IEnumerable <Point> GetExplosionLocations(ExplodableBase explodable)
        {
            var result = new List <Point> {
                explodable.Location
            };

            result.AddRange(CalculateExplosionRay(explodable, MoveDirection.Up));
            result.AddRange(CalculateExplosionRay(explodable, MoveDirection.Down));
            result.AddRange(CalculateExplosionRay(explodable, MoveDirection.Right));
            result.AddRange(CalculateExplosionRay(explodable, MoveDirection.Left));

            return(result);
        }
        private IEnumerable <Point> CalculateExplosionRay(ExplodableBase explodable, MoveDirection direction)
        {
            var currentPoint = explodable.Location;

            for (var i = 1; i <= explodable.ExplosionRadius; i++)
            {
                currentPoint = _locationService.GetNewLocation(currentPoint, direction);

                if (!_locationService.IsLocationValid(currentPoint))
                {
                    yield break;
                }

                yield return(currentPoint);

                if (_field.Board[currentPoint.X, currentPoint.Y] != BoardTile.Empty)
                {
                    yield break;
                }
            }
        }
        private void SetExplosion(ExplodableBase explodable)
        {
            var explosion = new Explosion
            {
                Center         = explodable.Location,
                BlastLocations = GetExplosionLocations(explodable)
            };

            _field.Explosions.Add(explosion);

            explodable.IsExploded = true;

            foreach (var explosionLocation in explosion.BlastLocations)
            {
                switch (_field.Board[explosionLocation.X, explosionLocation.Y])
                {
                case BoardTile.Regular:
                    _field.Board[explosionLocation.X, explosionLocation.Y] = BoardTile.Empty;
                    break;

                case BoardTile.Fortified:
                    _field.Board[explosionLocation.X, explosionLocation.Y] = BoardTile.Regular;
                    break;
                }

                _field.Bots.ForEach(bot =>
                {
                    if (bot.Location == explosionLocation)
                    {
                        bot.IsDead = true;
                    }
                });
            }

            SetChainedExplosions(explosion);
        }