Exemplo n.º 1
0
        public void Shoot()
        {
            var player = GetPlayer();

            if (player.Missiles.Count >= player.MissileLimit)
            {
                CommandFeedback = "Shot failed - too many missiles in flight.";
                return;
            }

            var missileX = X + 1; // center of the ship
            var missileY = (PlayerNumber == 1) ? Y - 1 : Y + 1;

            var missile = new Missile(PlayerNumber)
            {
                X = missileX,
                Y = missileY
            };

            player.Missiles.Add(missile);
            missile.OnDestroyedEvent += OnMissileDestroyed;

            try
            {
                GetMap().AddEntity(missile);
            }
            catch (CollisionException ex)
            {
                missile.Destroy();
                missile.ScoreKill(ex.Entity);
                ex.Entity.Destroy();
            }
        }
 public override void Update()
 {
     try
     {
         ProcessCommand();
     }
     catch (CollisionException e)
     {
         //if the ship moved and caused a collision exception, if it didn't collide with wall it should be destroyed.
         if (e.Entity.GetType() != typeof(Wall))
         {
             foreach (Entity entity in e.Entities)
             {
                 if (e.Entity.GetType() == typeof(Missile))
                 {
                     Missile m = (Missile)entity;
                     m.ScoreKill(this);
                     m.Destroy();
                 }
                 else
                 {
                     entity.Destroy();
                 }
             }
             this.Destroy();
         }
     }
 }
Exemplo n.º 3
0
        public void Shoot()
        {
            var player = GetPlayer();

            if (player.Missiles.Count >= player.MissileLimit)
            {
                CommandFeedback = "Shot failed - too many missiles in flight.";
                return;
            }

            var missileX = X + 1; // center of the ship
            var missileY = (PlayerNumber == 1) ? Y - 1 : Y + 1;

            var missile = new Missile(PlayerNumber)
            {
                X = missileX,
                Y = missileY
            };

            try
            {
                GetMap().AddEntity(missile);
                player.Missiles.Add(missile);
                missile.OnDestroyedEvent += OnMissileDestroyed;
            }
            catch (CollisionException ex)
            {
                missile.ScoreKill(ex.Entity);
                ex.Entity.Destroy();
            }
        }