示例#1
0
        /// <summary>
        /// метод вывода обновленного положения объектов в форму
        /// </summary>
        public static void Update()
        {
            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }

            foreach (Bullet b in _bullets)
            {
                b?.Draw();
            }

            if (pharmacy != null)
            {
                if (_ship.Collision(pharmacy))
                {
                    System.Media.SystemSounds.Exclamation.Play();
                    _ship.EnergeUp(rnd.Next(1, 10));
                    pharmacy = null;
                    i        = 0;
                }
            }

            for (int i = 0; i < _asteroids.Count; 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.Hand.Play();
                        _asteroids[i] = null;
                        _bullets.RemoveAt(j);
                        j--;
                        count++;
                        LogEvent($"{DateTime.Now.ToString()} уничтожен {_asteroids} !!!");
                    }
                }

                if (_asteroids[i] == null || !_ship.Collision(_asteroids[i]))
                {
                    continue;
                }
                else if (_asteroids[i] != null && _ship.Collision(_asteroids[i]))
                {
                    _ship?.EnergeLow(rnd.Next(1, 10));
                    System.Media.SystemSounds.Asterisk.Play();
                    _asteroids.RemoveAt(i);
                }

                if (_ship.Energy <= 0)
                {
                    _ship.Die();
                    LogEvent($"{DateTime.Now.ToString()} уничтожен {_ship} !!!");
                }
            }

            if (_asteroids == null)
            {
                List_length++;
                for (int i = 0; i < List_length; i++)
                {
                    int r = rnd.Next(0, 50);
                    _asteroids.Add(new Asteroid(new Point(1000, rnd.Next(0, maxValue: Height)), new Point(-r / 5, r), new Size(r, r)));
                }
            }


            #region HW3
            //    if (_asteroids[i] == null) continue;
            //    _asteroids[i].Update();
            //    if(_bullet != null && _bullet.Collision(_asteroids[i]))
            //    {
            //        System.Media.SystemSounds.Hand.Play();
            //        _asteroids[i] = null;
            //        _bullet= null;
            //        count++;
            //        LogEvent($"{DateTime.Now.ToString()} уничтожен {_asteroids} !!!");
            //        continue;
            //    }

            //    if (_ship.Collision(_asteroids[i]))
            //    {
            //        _ship?.EnergeLow(rnd.Next(1, 10));
            //        System.Media.SystemSounds.Asterisk.Play();

            //    }

            //    if (_ship.Energy <= 0)
            //    {
            //        _ship.Die();
            //        LogEvent($"{DateTime.Now.ToString()} уничтожен {_ship} !!!");
            //    }
            //}
            #endregion

            #region HW2
            //foreach  (Asteroid a in _asteroids)
            //{
            //    a.Update();

            //    if (a.Collision(_bullet))
            //    { SystemSounds.Hand.Play();
            //        a.Regeneretion();
            //        _bullet.Regeneretion();
            //    }
            //    _bullet.Update();
            //}
            #endregion
        }