/// <summary> /// Метод инициализации событий и добавления кнопок на основую форму /// </summary> /// <param name="form">Основная форма</param> public static void ControlsInit(Form form) { BtnList.Clear(); BtnList.Add(GameContinueBtn); BtnList.Add(NewGameBtn); BtnList.Add(RecordsBtn); BtnList.Add(ExitBtn); ShowMenu(form, true); // Показать меню foreach (var b in BtnList) { form.Controls.Add(b); } #region Описание событий // Событие нажатия "Начать игру" NewGameBtn.Click += (object sender, EventArgs e) => { ShowMenu(form, false); if (MessageBox.Show("Игра началась!\n" + Settings.GameRules, $"Привет, {Settings.UserName}!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) == DialogResult.OK) { Game.Restart(); } }; // Событие нажатия "Выход" ExitBtn.Click += (object sender, EventArgs e) => { if (MessageBox.Show("Вы уверены, что хотите выйти?", "Выход", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Application.Exit(); } }; // Событие нажатия "Продолжить игру" GameContinueBtn.Click += (object sender, EventArgs e) => { if (Game.GameStarting) { Game.Pause(); form.Focus(); } }; // Событие нажатия "Продолжить игру" RecordsBtn.Click += (object sender, EventArgs e) => { ShowRecordsFile(); }; // Событие нажатия клавиш form.KeyDown += (object sender, KeyEventArgs e) => { if (e.KeyCode == Keys.Space) { Game.Ship?.Fire(true); } if (e.KeyCode == Keys.Up) { Game.Ship?.Up(true); } if (e.KeyCode == Keys.Down) { Game.Ship?.Down(true); } if (e.KeyCode == Keys.Left) { Game.Ship?.Left(true); } if (e.KeyCode == Keys.Right) { Game.Ship?.Right(true); } if (e.KeyCode == Keys.Escape && Game.GameStarting) { Game.Pause(); } }; form.KeyUp += (object sender, KeyEventArgs e) => { if (e.KeyCode == Keys.Space) { Game.Ship?.Fire(false); } if (e.KeyCode == Keys.Up) { Game.Ship?.Up(false); } if (e.KeyCode == Keys.Down) { Game.Ship?.Down(false); } if (e.KeyCode == Keys.Left) { Game.Ship?.Left(false); } if (e.KeyCode == Keys.Right) { Game.Ship?.Right(false); } }; #endregion }