Example #1
0
        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;
        }
Example #2
0
        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;
                }
            }
        }
Example #3
0
 public ExplodableBase(ExplodableBase explodable)
 {
     Location = explodable.Location;
     ExplosionRadius = explodable.ExplosionRadius;
     IsExploded = explodable.IsExploded;
 }
Example #4
0
 public ExplodableBase(ExplodableBase explodable)
 {
     Location        = explodable.Location;
     ExplosionRadius = explodable.ExplosionRadius;
     IsExploded      = explodable.IsExploded;
 }
Example #5
0
        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);
        }