Пример #1
0
        //добавим дополнительно метод Load, в котором реализуем инициализацию наших объектов:
        public static void Load()
        {
            Random Random = new Random();

            gamer       = new Gamer();
            gamer.Name  = "Player";
            gamer.Score = 0;

            int starsCount = 50;

            _stars = new Star[starsCount];// 50 объектов
            for (int i = 0; i < _stars.Length; i++)
            {
                int _x     = Random.Next(0, Width); // случайное место
                int _y     = i * Height / starsCount;
                int _layer = Random.Next(0, 5);     //сдучайный слой

                _stars[i] = new Star(new Point(_x, _y), new Point(10, 0), new Size(1, 1), _layer);

                //отрисовка
            }

            int asteroidCount = 10;

            //_asteroids = new Asteroid[asteroidCount];

            CreateAstroid(asteroidCount);

            {
                int _x     = 10;
                int _y     = Height / 2;
                int _layer = 0;

                _ship = new Ship(new Point(_x, _y), new Point(10, 10), new Size(20, 20), _layer);
            }

            _medecine = CreateMedecine();
        }
Пример #2
0
        public static void Update()
        {
            var random = new Random();

            foreach (BaseObject obj in _stars)
            {
                obj.Update();
            }
            foreach (Bulet b in _bullets)
            {
                b?.Update();
            }

            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 (_bullets[j] != null && _asteroids[i] != null && _bullets[j].Collision(_asteroids[i]))//попал по астероиду
                    {
                        _asteroids[i] = null;

                        _bullets[j] = null;
                        gamer.Score++;
                        continue;
                    }
                }



                if (_asteroids[i] == null || !_ship.Collision(_asteroids[i]))
                {
                    continue;
                }

                _ship?.EnergyLow(random.Next(1, 10));
                if (_ship.Energy <= 0)
                {
                    _ship?.Die();
                }
            }

            for (int i = 0; i < _asteroids.Count; i++)
            {
                if (_asteroids[i] != null)
                {
                    break;
                }
                if (i == _asteroids.Count - 1)
                {
                    CreateAstroid(_asteroids.Count + 1);
                }
            }

            if (_medecine != null && _ship.Collision(_medecine))
            {
                _ship?.EnergyHight(random.Next(1, 10));
            }

            _ship?.Update();
            foreach (Bulet b in _bullets)
            {
                b?.Update();
            }
            _medecine?.Update();
            if (_medecine != null && _medecine._Pos.X < 0)
            {
                _medecine = null;
            }
            if (_medecine == null)
            {
                _medecine = CreateMedecine();
            }
        }