示例#1
0
        private static void AddMedicineChest()
        {
            if (_medicineChest != null)
            {
                return;
            }

            int r = Rnd.Next(4, 10);

            _medicineChest = new MedicineChest(
                new Point(Game.Width, Rnd.Next(25, Game.Height - 25)),
                new Point(r, r),
                new Size(50, 50));
        }
示例#2
0
        public static void Update()
        {
            //_backGround.Update();

            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }

            foreach (Bullet obj in _bullets)
            {
                obj.Update();
            }

            _medicineChest?.Update();
            if (!_medicineChest?.IsActive ?? false)
            {
                _medicineChest = null;
            }

            if (_medicineChest != null && _ship.Collision(_medicineChest))
            {
                System.Media.SystemSounds.Beep.Play();
                _ship.IncreaseEnergy(_medicineChest.Energy);
                _medicineChest = null;
            }

            if (_asteroids.Count == 0)
            {
                AddAsteroids(_startAsteroidsCount + 1);
            }

            foreach (Asteroid asteroid in _asteroids)
            {
                asteroid.Update();

                var bullet = _bullets.FirstOrDefault(b => b.Collision(asteroid));
                if (bullet != null)
                {
                    System.Media.SystemSounds.Hand.Play();
                    asteroid.IsDestroyed = true;
                    _bullets.Remove(bullet);
                    _ship.AddScore();
                    continue;
                }

                if (!_ship.Collision(asteroid))
                {
                    continue;
                }

                asteroid.IsDestroyed = true;
                _ship.ReduceEnergy(Rnd.Next(1, 20));
                System.Media.SystemSounds.Asterisk.Play();
                if (_ship.Energy <= 0)
                {
                    _ship.Die();
                }
            }
            _asteroids.RemoveAll(a => a.IsDestroyed);
        }