Ejemplo n.º 1
0
        public static void Load()
        {
            _objs = new BaseObject[30];
            heal  = new HealBox();
            var rnd = new Random();

            AsteroidInit();
            for (var i = 0; i < _objs.Length; i++)
            {
                int r = rnd.Next(5, 50);
                _objs[i] = new Star();
            }
            _ship.print = MessagePrint;
        }
Ejemplo n.º 2
0
        public static void Update()
        {
            var rnd = new Random();

            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }
            foreach (Bullet b in _bullets)
            {
                b.Update();
            }
            if (heal == null & rnd.Next(0, 100) > 90)
            {
                heal = new HealBox();
            }
            heal?.Update();
            for (int i = 0; i < _bullets.Count; i++)
            {
                if (_bullets[i].Pos.X > Game.Width)
                {
                    _bullets.RemoveAt(i);
                    i--;
                }
            }
            for (int i = 0; i < _asteroids.Count; i++)
            {
                _asteroids[i].Update();
                for (int j = 0; j < _bullets.Count; j++)
                {
                    if (_bullets[j].Collision(_asteroids[i]))
                    {
                        System.Media.SystemSounds.Hand.Play();
                        _asteroids[i].print("Asteroid destroy");
                        _asteroids.RemoveAt(i);
                        i--;
                        _bullets.RemoveAt(j);
                        j--;
                        _ship.ScoreUp(5);
                        continue;
                    }
                }
            }
            for (int i = 0; i < _asteroids.Count; i++)
            {
                if (_ship.Collision(_asteroids[i]))
                {
                    _ship.EnergyLow(Rnd.Next(1, 10));
                    _asteroids.RemoveAt(i);
                    i--;
                    System.Media.SystemSounds.Asterisk.Play();
                    if (_ship.Energy <= 0)
                    {
                        _ship.Die();
                    }
                }
            }
            if (_asteroids.Count == 0)
            {
                asteroidCount++;
                AsteroidInit();
            }
            if (heal != null)
            {
                if (_ship.Collision(heal))
                {
                    heal = null;
                    _ship.Heal(10);
                }
            }
        }