Beispiel #1
0
        static void Main(string[] args)
        {
            CareTaker caretaker = new CareTaker();
            User      p         = new User();

            Console.WriteLine("Changing name to Pedro");
            p.Name = "Pedro";
            Console.WriteLine("Changing name to Juan");
            p.Name = "Juan";

            caretaker.addMemento(p.saveToMemento());

            Console.WriteLine("Changing name to Carlos");
            p.Name = "Carlos";

            caretaker.addMemento(p.saveToMemento());

            Console.WriteLine("Changing name to Octavio");
            p.Name = "Octavio";

            Memento m1 = caretaker.getMemento(0);
            Memento m2 = caretaker.getMemento(1);

            Console.WriteLine(m1.SavedState);
            Console.WriteLine(m2.SavedState);

            Console.ReadKey();
        }
Beispiel #2
0
        // Use this for initialization
        void Start()
        {
            //Originator originator = new Originator();
            //originator.SetState("State1");
            //originator.ShowState();

            //Memento memento = originator.CreateMemento();
            //originator.SetState("State2");
            //originator.ShowState();

            //originator.SetMemento(memento);
            //originator.ShowState();

            CareTaker  careTaker  = new CareTaker();
            Originator originator = new Originator();

            originator.SetState("state1");
            originator.ShowState();

            careTaker.AddMemento("1.0", originator.CreateMemento());

            originator.SetState("state2");
            originator.ShowState();

            careTaker.AddMemento("2.0", originator.CreateMemento());

            originator.SetMemento(careTaker.GetMemento("2.0"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // player has completed level 1
            Player player = new Player();

            player.Level  = 1;
            player.Score  = 100;
            player.Health = "100%";
            Console.WriteLine("----------- Player info after completing level 1 ---------------------");
            player.DisplayPlayerInfo();
            // when player completes any level then create checkpoint for that level.
            CareTaker careTaker = new CareTaker();

            careTaker.LevelMarker = player.CreateMarker(player);

            // sleep is only added to show some delay..
            Thread.Sleep(2000);

            player.Level  = 2;
            player.Score  = 130;
            player.Health = "80%";
            Console.WriteLine("--------------- Player info in level 2 --------------------------------");
            player.DisplayPlayerInfo();

            // if players loses all the lifeline then restore the game from level 1
            player.RestoreLevel(careTaker.LevelMarker);
            Console.WriteLine("------------- Player info after restoring level 1 data ----------------");
            player.DisplayPlayerInfo();

            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Book book = new Book
            {
                Isbn   = "12345",
                Title  = "Sefiller",
                Author = "Victor Hugo"
            };

            book.ShowBook();
            CareTaker history = new CareTaker();

            history.Mementon = book.CreateUndo();
            book.Isbn        = "54321";
            book.Title       = "VICTOR HUGO";
            book.ShowBook();
            book.RestoreFromUndo(history.Mementon);
            book.ShowBook();



            Console.ReadLine();
        }