Exemple #1
0
        static void Main(string[] args)
        {
            Hero1       hero    = new Hero1();
            GameHistory history = new GameHistory();

            hero.Shot();

            history.History.Push(hero.SaveState());


            for (int i = 0; i < 3; i++)
            {
                hero.Shot();
            }

            hero.RestoreState(history.History.Pop());

            for (int i = 0; i < 3; i++)
            {
                hero.Shot();
            }



            Console.ReadKey(true);
        }
Exemple #2
0
        public static void Test()
        {
            Hero        hero        = new Hero(3, 5);
            GameHistory gameHistory = new GameHistory();

            gameHistory.History.Push(hero.Save());

            hero.Shoot();
            gameHistory.History.Push(hero.Save());

            hero.Damage();
            hero.Shoot();
            hero.Shoot();
            gameHistory.History.Push(hero.Save());

            hero.Damage();
            hero.Damage();
            hero.Damage();

            hero.Load(gameHistory.History.Peek());

            hero.Damage();
            hero.Shoot();
            gameHistory.History.Pop();
            hero.Load(gameHistory.History.Peek());
        }
        static void Main(string[] args)
        {
            Hero hero = new Hero();

            hero.Shoot();
            GameHistory game = new GameHistory();

            Console.WriteLine("\n");

            game.History.Push(hero.SaveState());
            Console.WriteLine("\n");

            hero.Shoot();
            Console.WriteLine("\n");

            hero.RestoreState(game.History.Pop());
            Console.WriteLine("\n");

            hero.Shoot();
            Console.WriteLine("\n");

            game.History.Push(hero.SaveState());
            Console.WriteLine("\n");

            hero.Shoot();
            Console.WriteLine("\n");

            hero.RestoreState(game.History.Pop());
            Console.WriteLine("\n");

            hero.Shoot();
            Console.WriteLine("\n");

            Console.Read();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Hero hero = new Hero();

            hero.Shoot(); // делаем выстрел, осталось 9 патронов
            GameHistory game = new GameHistory();

            game.History.Push(hero.SaveState()); // сохраняем игру

            hero.Shoot();                        //делаем выстрел, осталось 8 патронов

            hero.RestoreState(game.History.Pop());

            hero.Shoot(); //делаем выстрел, осталось 8 патронов

            game.History.Push(hero.SaveState());

            hero.Shoot();

            hero.addPatron();



            Console.Read();
        }
Exemple #5
0
        static void LevelThree(GameHistory hist)
        {
            Console.WriteLine("Level three");

            Inventory inv = new Inventory(5);

            inv.RestoreState(hist.InventoryMemento);
            inv.Print();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            GameHistory hist = new GameHistory();

            LevelOne(hist);
            LevelTwo(hist);
            LevelThree(hist);

            Console.ReadLine();
        }
Exemple #7
0
        static void LevelOne(GameHistory hist)
        {
            Console.WriteLine("Level one");
            Inventory inv = new Inventory(5);

            for (int i = 0; i < 5; i++)
            {
                inv.Add(new Item($"Item #: {i}"));
            }
            inv.Print();

            hist.InventoryMemento = inv.SaveState();
        }
Exemple #8
0
        static void LevelTwo(GameHistory hist)
        {
            Console.WriteLine("Level two");

            Inventory inv = new Inventory(5);

            inv.RestoreState(hist.InventoryMemento);

            inv.RemoveAt(4);
            inv.RemoveAt(2);
            inv.Print();

            hist.InventoryMemento = inv.SaveState();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            Hero        Rembo       = new Hero();
            GameHistory GameHistory = new GameHistory();

            GameHistory.History.Push(Rembo.SaveState());

            Play(Rembo);

            Rembo.RestoreState(GameHistory.History.Pop());

            Play(Rembo);
            Console.ReadKey();
        }
Exemple #10
0
        private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Title           = "Memento";

            var hero = new Hero();

            // Делаем выстрел, осталось 9 патронов
            hero.Shoot();
            var game = new GameHistory();

            // Сохраняем игру
            game.History.Push(hero.SaveState());

            // Делаем выстрел, осталось 8 патронов
            hero.Shoot();

            hero.RestoreState(game.History.Pop());

            // Делаем выстрел, осталось 8 патронов
            hero.Shoot();

            Console.ReadKey();
        }