Exemplo n.º 1
0
        /// <summary>
        /// Инициализация пространства для отрисовки.
        /// </summary>
        /// <param name="form"></param>
        public static void Init(Form form)
        {
            form.KeyDown += Form_KeyDown;

            Graphics g;

            _context = BufferedGraphicsManager.Current;
            g        = form.CreateGraphics();
            if (form.Width > 1600 || form.Width < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            Width = form.Width;
            if (form.Height > 1600 || form.Height < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            Height = form.Height;
            Buffer = _context.Allocate(g, new Rectangle(0, 0, Width, Height));

            Load(BackGround.CreateObjectsList());

            timer = new Timer()
            {
                Interval = 20
            };
            timer.Tick += Timer_Tick;
            timer.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Обработчик события смерти игрока
        /// </summary>
        private static void Finish()
        {
            Game.ChangeGameStatus();
            timer.Stop();
            MessageBox.Show("Ты умер.");

            // Проверяем бинарный файл с выигравшими
            // Если есть свободное место или результат больше, чем когда-либо,
            // выводим форму с инпутом (через ShowDialog, не забыть у кнопок:
            // "You have to set the DialogResult in the Button handler."
            //Form2 testDialog = new Form2();

            //// Show testDialog as a modal dialog and determine if DialogResult = OK.
            //if (testDialog.ShowDialog(this) == DialogResult.OK)
            //{
            //    // Read the contents of testDialog's TextBox.
            //    this.txtResult.Text = testDialog.TextBox1.Text;
            //}
            //else
            //{
            //    this.txtResult.Text = "Cancelled";
            //}
            //testDialog.Dispose();

            // Потом добавлние результата в файл и запись.
            // А теперь старт заново.


            Load(BackGround.CreateObjectsList());
            timer.Start();
            heroShip.Health = 100;
            heroShip.Score  = 0;
        }