Beispiel #1
0
        public static void Init(Form form)
        {
            // Графическое устройство для вывода графики
            Graphics g;

            // предоставляет доступ к главному буферу графического контекста для текущего приложения
            _context = BufferedGraphicsManager.Current;
            g        = form.CreateGraphics(); // Создаём объект - поверхность рисования и связываем его с формой
                                              // Запоминаем размеры формы
            Width  = form.Width;
            Height = form.Height;
            // Связываем буфер в памяти с графическим объектом.
            // для того, чтобы рисовать в буфере
            Buffer = _context.Allocate(g, new Rectangle(0, 0, Width, Height));

            Load();

            //Timer timer = new Timer { Interval = 100 };
            _timer.Start();
            _timer.Tick += Timer_Tick;

            form.KeyDown    += Form_KeyDown;
            Ship.MessageDie += Finish;
            GameLogDelegate msg = new GameLogDelegate(GameLog);

            msg.Invoke("New Game!");
        }
Beispiel #2
0
        private static void Form_KeyDown(object sender, KeyEventArgs e)
        {
            GameLogDelegate msg = new GameLogDelegate(GameLog);

            //if (e.KeyCode == Keys.ControlKey) _bullet = new Bullet(new Point(_ship.Rect.X + 10, _ship.Rect.Y + 4), new Point(4, 0), new Size(4, 1));
            if (e.KeyCode == Keys.ControlKey)
            {
                _listBullets.Add(new Bullet(new Point(_ship.Rect.X + 10, _ship.Rect.Y + 4), new Point(4, 0), new Size(4, 1)));
                if (_listBullets.Count > 100)
                {
                    _listBullets.Remove(_listBullets[0]);
                }
            }

            if (e.KeyCode == Keys.Up)
            {
                _ship.Up();
            }
            if (e.KeyCode == Keys.Down)
            {
                _ship.Down();
            }
            if (e.KeyCode == Keys.Space && _ship.CountFirstAidKit > 0)
            {
                _ship.FirstAidKit();
                //GameLog("You used First Aid Kid and recover 15 points of Energy");
                msg.Invoke("You used First Aid Kid and recover 15 points of Energy");
            }
        }
Beispiel #3
0
        public static void Update()
        {
            GameLogDelegate msg = new GameLogDelegate(GameLog);

            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }
            _bullet?.Update();
            int nullCount = 0;

            //for (var i = 0; i < _asteroids.Length; i++)
            for (var i = 0; i < _listAsteroids.Count; i++)
            {
                //if (_asteroids[i] == null) continue;
                if (_listAsteroids[i] == null)
                {
                    nullCount++;
                    if (nullCount == _listAsteroids.Count)
                    {
                        var rand = new Random();
                        var r    = rand.Next(5, 50);
                        _listAsteroids.Add(new Asteroid(new Point(1000, rand.Next(0, Game.Height)), new Point(-r / 5, r), new Size(r, r)));
                        for (int j = 0; j < _listAsteroids.Count; j++)
                        {
                            r = rand.Next(5, 50);
                            _listAsteroids[j] = new Asteroid(new Point(1000, rand.Next(0, Game.Height)), new Point(-r / 5, r), new Size(r, r));
                        }
                    }
                    continue;
                }
                //_asteroids[i].Update();
                _listAsteroids[i].Update();
                if (_bullet != null && _bullet.Collision(_listAsteroids[i]))
                {
                    System.Media.SystemSounds.Hand.Play();
                    //_asteroids[i] = null;
                    _listAsteroids[i] = null;
                    _bullet           = null;
                    _ship?.AddScore(100);
                    //GameLog($"You get 100 points of score for destroying Asteroid!");
                    msg.Invoke($"You get 100 points of score for destroying Asteroid!");
                    continue;
                }
                if (!_ship.Collision(_listAsteroids[i]))
                {
                    continue;
                }
                var rnd = new Random();
                int dmg = rnd.Next(1, 10);
                _ship?.EnergyLow(dmg);
                System.Media.SystemSounds.Asterisk.Play();
                //GameLog($"The Ship was damaged on {dmg} points of Energy");
                msg.Invoke($"The Ship was damaged on {dmg} points of Energy");
                if (_ship.Energy <= 0)
                {
                    _ship?.Die();
                }
            }
        }
Beispiel #4
0
        public static void Finish()
        {
            GameLogDelegate msg = new GameLogDelegate(GameLog);

            _timer.Stop();
            Buffer.Graphics.DrawString("The End", new Font(FontFamily.GenericSansSerif, 60,
                                                           FontStyle.Underline), Brushes.White, 200, 100);
            Buffer.Render();
            msg.Invoke("The End");
        }
Beispiel #5
0
        private List <PlayerViewModel> InitializePlayers()
        {
            var initPlayers = new List <PlayerViewModel>();

            for (int ID = 0; ID < Config.NumberOfPlayers; ID++)
            {
                var playerInfo = Config.PlayerInfoList[ID];
                var newPlayer  = new PlayerModel(playerInfo.Name, ID, SaboteurPartyList[ID]);
                initPlayers.Add(new PlayerViewModel(newPlayer, (GameMode)playerInfo.GameMode));
                GameStart  += initPlayers[ID].Window.Show;
                GameStart  += initPlayers[ID].DrawStartHands;
                PublicLog  += initPlayers[ID].PrivateLog;
                ViewUpdate += initPlayers[ID].UpdateTreasureVisibility;
                ViewUpdate += initPlayers[ID].UpdateMyView;
            }
            return(initPlayers);
        }