示例#1
0
        protected override void OnMoved(Bullet afterMove)
        {
            if (DeltaTime == TimeSpan.Zero)
            {
                base.OnMoved(afterMove);
                return;
            }
            Debug.WriteLine($"Released grenade deltaTime.TotalSeconds = {DeltaTime.TotalSeconds}");
            var distanceAfterMove = afterMove.DistanceTo(myTarget) * DeltaTime.TotalSeconds;

            Debug.WriteLine($"Released grenade after move distance * deltaTime.TotalSeconds = {distanceAfterMove}");
            if (distanceAfterMove < 3)
            {
                var botsToDamage = Battlefield.Bots
                                   .OfType <Bot>()
                                   .Where(bot => afterMove.DistanceTo(bot) < myExplosionRadius)
                                   .ToList();
                if (botsToDamage.Any())
                {
                    botsToDamage.ForEach(bot => bot.TakeDamageFrom(this));
                }
                Battlefield.Remove(this);
                Battlefield.Add(new Explosion(Battlefield, Position));
            }
            else
            {
                base.OnMoved(afterMove);
            }
        }
示例#2
0
 private void Respawn()
 {
     Init(Battlefield, BotAI);
     Position = new Point(Home.Position.X, Home.Position.Y);
     Battlefield.Add(this);
     OnRespawned();
 }
示例#3
0
 public void DropDownResource()
 {
     Speed = MaxSpeed;
     OnResourceDropped(Resource);
     Battlefield.Add(new Resource(new Point(Position.X, Position.Y)));
     Resource = null;
 }
示例#4
0
        public Round(IBotAIFactory botAIFactory)
        {
            ElapsedTime = TimeSpan.Zero;
            var botAIs = botAIFactory.CreateBotAIs();
            var width  = double.Parse(ConfigurationManager.AppSettings["BattlefieldWidth"]);
            var height = double.Parse(ConfigurationManager.AppSettings["BattlefieldHeight"]);

            Battlefield = new Battlefield(width, height);
            Bots        = new List <Bot>();
            myRandom    = new Random();
            foreach (var botAI in botAIs)
            {
                var bot = new Bot(Battlefield, botAI);
                Battlefield.Add(bot);
                Bots.Add(bot);
            }
            AddHospital();

            InitializePositions();

            myTurnDelay = double.Parse(ConfigurationManager.AppSettings["TurnDelayInMilliseconds"]);
            myTimeout   = TimeSpan
                          .FromSeconds(int.Parse(
                                           ConfigurationManager.AppSettings["RoundTimeoutInSeconds"]));
            myWeaponsCount     = int.Parse(ConfigurationManager.AppSettings["WeaponsCount"]);
            myResourceCount    = int.Parse(ConfigurationManager.AppSettings["ResourceCount"]);
            myFirstAidKitCount = int.Parse(ConfigurationManager.AppSettings["FirstAidKitCount"]);
        }
示例#5
0
 private void Aim()
 {
     if (IsDead)
     {
         return;
     }
     myRemainingAimTime -= DeltaTime;
     if (myRemainingAimTime <= TimeSpan.Zero)
     {
         var bullets = myWeapon.Fire(this, myTarget);
         foreach (var bullet in bullets)
         {
             Battlefield.Add(bullet);
         }
     }
 }