Beispiel #1
0
        /// <summary>
        /// Совокупный метод, определяющий движения объектов по игровому полю и их взаимодействие
        /// </summary>
        public static void Update()
        {
            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }

            //foreach (Asteroid asteroid in _asteroids)
            for (int i = 0; i < _asteroids.Count; i++)
            {
                _asteroids[i].Update();
                foreach (Bullet bullet in _bullets)
                {
                    bullet.Update();
                    if (bullet.Collision(_asteroids[i]))
                    {
                        System.Media.SystemSounds.Asterisk.Play();
                        _bullets.Remove(bullet);
                        _asteroids.RemoveAt(i);
                        Ship.Journal($"Asteroid Destroyed! Total: {++asteroids_destroyed}");
                        break;
                    }
                }
                if (i >= _asteroids.Count)
                {
                    break;
                }
                if (!_ship.Collision(_asteroids[i]))
                {
                    continue;
                }
                _ship?.EnergyChange(r.Next(1, 10));
                Ship.Journal($"BOOM! Energy: {_ship.Energy}");
                _asteroids.RemoveAt(i);
                System.Media.SystemSounds.Asterisk.Play();
                if (_ship.Energy <= 0)
                {
                    _ship?.Die();
                }
            }
            if (_asteroids.Count == 0)
            {
                AsteroidsLoad();
            }

            _heal?.Update();
            if (_heal != null && _ship.Collision(_heal))
            {
                _ship?.EnergyChange(-20);
                _heal = null;
            }
            Buffer.Render();
        }
Beispiel #2
0
        /// <summary>
        /// Метод, инициализирующий группу астероидов
        /// </summary>
        private static void AsteroidsLoad()
        {
            //Шанс на спавн аптечки ~ 20% при условии, что энергия корабля меньше 80, спавн только между волнами астероидов
            if (_ship.Energy < 80 && r.Next(0, 100) < 20)
            {
                _heal = new Heal(new Point(1000, r.Next(50, 750)), new Point(ASTEROID_VELOCITY * 2, 0), new Size(20, 20));
            }

            for (int i = 0; i < asteroids_count; i++)
            {
                _asteroids.Add(new Asteroid(new Point(1000 + i * 50, r.Next(50, 750)), new Point(ASTEROID_VELOCITY, 0), new Size(20, 20)));
            }
            asteroids_count++;
        }