Beispiel #1
0
        public void Undo(GameOriginator gameOriginator)
        {
            IMemento lastMemento = mementos.Last();

            mementos.Remove(lastMemento);
            gameOriginator.RestoreGame(lastMemento);
        }
        static void Main(string[] args)
        {
            GameOriginator gameOriginator = new GameOriginator(new GameState(0, "Silp", DateTime.Now));
            GameCaretaker  caretaker      = new GameCaretaker();

            continueWithKey();
            caretaker.MakeBackup(gameOriginator.Save());
            gameOriginator.NextLevel();
            continueWithKey();
            caretaker.MakeBackup(gameOriginator.Save());
            gameOriginator.NextLevel();
            gameOriginator.NextLevel();
            gameOriginator.NextLevel();
            gameOriginator.DescribeCurrentLevel();
            caretaker.ShowHistory();
            Console.WriteLine("Making undo");
            continueWithKey();
            caretaker.Undo(gameOriginator);
            Console.WriteLine("Making another undo");
            continueWithKey();
            caretaker.Undo(gameOriginator);
            caretaker.ShowHistory();
            continueWithKey();
        }