Exemplo n.º 1
0
        /// <summary>
        /// Обновляем объекты на экране
        /// </summary>
        public static void Update()
        {
            foreach (Bullet b in _bullets)
            {
                b.Update();
            }

            for (var i = 0; i < _lasteroids.Count; i++)
            {
                if (_lasteroids[i] == null)
                {
                    continue;
                }

                _lasteroids[i].Update();

                if (_lasteroids[i].Collision(_ship))
                {
                    System.Media.SystemSounds.Asterisk.Play();
                    var rnd = new Random();
                    _ship?.EnergyLow(rnd.Next(10, 50));
                    _lasteroids[i].Pos.X = Width;
                    _lasteroids[i].Pos.Y = Height;
                    _log += ShipHit;
                    if (_ship.Energy <= 0)
                    {
                        _ship?.Die();
                    }
                }

                for (int j = 0; j < _bullets.Count; j++)
                {
                    if (_lasteroids[i] != null && _bullets[j].Collision(_lasteroids[i]))
                    {
                        System.Media.SystemSounds.Hand.Play();
                        _bullets.RemoveAt(j);
                        _lasteroids.RemoveAt(i);
                        score++;
                        if (score > CurRec)
                        {
                            CurRec = score;
                        }
                        _log += Hit;
                        j--;
                        if (_lasteroids.Count == 0)
                        {
                            AsterCount++;
                            mspeed++;
                            CreateAsteroid(AsterCount, mspeed);
                        }
                        break;
                    }
                }

                if (_medkit.Collision(_ship))
                {
                    System.Media.SystemSounds.Exclamation.Play();
                    _ship?.EnergyHigh(25);
                    _medkit.Pos.X = Game.Width;
                    _medkit.Pos.Y = rnd.Next(0, Game.Height);
                }
            }
        }