/// <summary> /// Обработка нажатия клавиш /// </summary> private void ProcessingKeystrokes() { if (Keyboard.Escape) { StateOfGame = StateOfGame.Menu; Menu.MenuControl.BringToFront(); Thread.Sleep(100); } else if (Keyboard.Enter && menu.StateMenu == StateMenu.SaveGame) { timer.Stop(); // Сериализация var stream = new FileStream("Serialized", FileMode.Create); var formatter = new BinaryFormatter(); formatter.Serialize(stream, level); stream.Close(); menu.StateMenu = StateMenu.Game; StateOfGame = StateOfGame.Menu; Menu.MenuControl.BringToFront(); Thread.Sleep(100); timer.Start(); } else if (Keyboard.Enter && menu.StateMenu == StateMenu.LoadGame) { timer.Stop(); // Десериализвция level.Clear(); var stream = new FileStream("Serialized", FileMode.Open); var formatter = new BinaryFormatter(); level = formatter.Deserialize(stream) as Level; stream.Close(); menu.StateMenu = StateMenu.Game; StateOfGame = StateOfGame.Menu; Menu.MenuControl.BringToFront(); Thread.Sleep(100); level.InitDictionaru(); timer.Start(); } else if (Keyboard.Enter && StateOfGame == StateOfGame.GameOver) { level.LodLevel(); StateOfGame = StateOfGame.Menu; Menu.MenuControl.BringToFront(); Thread.Sleep(100); } else if (Keyboard.Enter && StateOfGame == StateOfGame.Menu && menu.StateMenu == StateMenu.Game) { StateOfGame = StateOfGame.Game; screenGame.BringToFront(); menu.ResetPosition(); } }
/// <summary> /// Конструктор /// </summary> /// <param name="form">Родительская Forma</param> public BattleCity(Form form) { form.ClientSize = new Size(SizeGame.WidtchWindowGame, SizeGame.HeighWindowGame); form.Icon = Properties.Resources.Ico; form.StartPosition = FormStartPosition.CenterScreen; form.Text = "Battle City"; level = new Level(); level.LodLevel(); menu = new Menu(form); gameOver = new GameOver(form); screenGame = new ScreenGame(form); StateOfGame = StateOfGame.Menu; Menu.MenuControl.BringToFront(); }