示例#1
0
        static public void Init(Form form)
        {
            Graphics g;

            context = BufferedGraphicsManager.Current;
            g       = form.CreateGraphics();
            Width   = form.Width;
            Height  = form.Height;


            // проверка на задание размера экрана
            //if (Width > 1000 || Height > 1000 || Width < 0 || Height < 0)
            //{
            //    throw new ArgumentOutOfRangeException("Границы экрана привысили допустимые значения");
            //}

            MessageToLog    += log;
            MessageToLog    += LogToFile;
            Ship.MessageDie += Ship.Message_Die;
            Ship.MessageDie += LogToFile;

            form.KeyDown += Form_KeyDown;
            buffer        = context.Allocate(g, new Rectangle(0, 0, Width, Height));
            Load();
            timer          = new Timer();
            timer.Interval = 50;
            timer.Tick    += Timer_Tick;
            timer.Start();
            LogToFile_Clear("Start loging at ");
            MessageToLog.Invoke("Started new game");
        }
示例#2
0
        static public void Update()
        {
            foreach (BaseObject obj in objs)
            {
                obj.Update();
            }

            if (asteroids.Count != 0)
            {
                for (int i = 0; i < bullets.Count; i++)
                {
                    for (int j = 0; j < asteroids.Count; j++)
                    {
                        if (bullets[i] != null && bullets[i].Collision(asteroids[j]))
                        {
                            System.Media.SystemSounds.Asterisk.Play();
                            asteroids.RemoveAt(j);
                            bullets[i] = null;
                            score++;
                            MessageToLog.Invoke("Bullet hit an asteroid");
                            MessageToLog.Invoke("Asteroid crashed");
                        }
                    }
                }
            }
            else
            {
                asteroidsCount++;
                AsteroidsLoad();
            }

            for (int i = 0; i < asteroids.Count; i++)
            {
                if (ship.Collision(asteroids[i]))
                {
                    ship.EnergyLow(50);
                    asteroids.RemoveAt(i);
                    MessageToLog.Invoke("Ship collided with an asteroid");
                }
            }

            if (ship.Collision(medPack))
            {
                System.Media.SystemSounds.Hand.Play();
                ship.EnergyHeight(50);
                medPack = new MedPack(new Point(rnd.Next(Width, Width + 10), rnd.Next(20, Height - 20)), new Point(-4, 0), new Size(50, 50));
                MessageToLog.Invoke("Ship got medpack");
            }

            for (int i = 0; i < bullets.Count; i++)
            {
                if (bullets[i] != null)
                {
                    bullets[i].Update();
                }
                else
                {
                    bullets.RemoveAt(i);
                }
            }

            foreach (Asteroid a in asteroids)
            {
                a.Update();
            }
            medPack?.Update();
        }