Exemplo n.º 1
0
        /// <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();
            }
        }