Ejemplo n.º 1
0
        public static void Update()
        {
            Random rnd = new Random();

            foreach (BaseObject baseObject in baseObjects)
            {
                baseObject.Update();
            }
            foreach (Bullet bullet in _bullets)
            {
                bullet?.Update();
            }
            firstAidKit?.Update();
            for (int i = 0; i < asteroids.Length; i++)
            {
                if (asteroids[i] == null)
                {
                    continue;
                }
                asteroids[i].Update();
                for (int j = 0; j < _bullets.Count; j++)
                {
                    if (asteroids[i] != null && _bullets[j].Collision(asteroids[i]))
                    {
                        System.Media.SystemSounds.Beep.Play();
                        _bullets.RemoveAt(j);
                        asteroids[i] = null;
                        j--;
                    }
                }
                if (asteroids[i] != null && !ship.Collision(asteroids[i]))
                {
                    continue;
                }
                if (asteroids[i] != null && ship.Collision(asteroids[i]))
                {
                    ship.EnergyLow(rnd.Next(1, 10));
                    System.Media.SystemSounds.Asterisk.Play();
                }

                if (ship.Energy <= 0)
                {
                    ship?.Die();
                }
            }
            if (asteroids.All(p => p == null))
            {
                Random random = new Random();
                int    r      = random.Next(5, 50);
                count++;
                asteroids = new Asteroid[count];
                for (int i = 0; i < asteroids.Length; i++)
                {
                    asteroids[i] = new Asteroid(new Point(600, random.Next(0, Height)), new Point(-r, r), new Size(50, 50));
                    asteroids[i].Update();
                }
            }
            if (firstAidKit != null && ship.Collision(firstAidKit))
            {
                ship.EnergyHigh(rnd.Next(0, 30));
                firstAidKit = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Метод обновляет координаты объектов
        /// </summary>
        public static void Update()
        {
            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }
            foreach (Bullet b in _bullets)
            {
                b.Update();
            }

            if (asteroidsArr.Length != 0)
            {
                for (var i = asteroidsArr.Length - 1; i >= 0; i--)
                {
                    asteroidsArr[i].Update();
                    if (_ship.Collision(asteroidsArr[i]))
                    {
                        asteroidsArr.AsteroidDestruction(i);
                        var rnd = new Random();
                        _ship?.EnergyLow(rnd.Next(10, 20));
                        System.Media.SystemSounds.Asterisk.Play();
                    }
                    else
                    {
                        for (int j = _bullets.Count - 1; j >= 0; j--)
                        {
                            if (_bullets[j].Collision(asteroidsArr[i]))
                            {
                                System.Media.SystemSounds.Hand.Play();
                                asteroidsArr.AsteroidDestruction(i);
                                _bullets.RemoveAt(j);
                                _ship.ScoreChange(10);
                                if (_ship.Energy < 100 && _fak == null)
                                {
                                    var rnd = new Random();
                                    _fak = new FirstAidKit(new Point(Width, rnd.Next(10, Height - 10)), new Point(-10, 0), new Size(50, 50), _images[9]);
                                }
                                break;
                            }
                        }
                    }
                    if (_ship.Energy <= 0)
                    {
                        _ship?.Die();
                    }
                }
            }
            else
            {
                asteroidsArr.AddAsteroids(asteroidsArr.numbOfAsteroids + 1, Width, Height, _images[7]);
            }
            if (_fak != null)
            {
                if (_ship.Collision(_fak))
                {
                    _ship.Heal(_fak);
                    _fak = null;
                }
            }
            _fak?.Update();
        }