Пример #1
0
        static void Main(string[] args)
        {
            GameRole gr = new GameRole();

            gr.InitState();
            gr.StateDisplay();

            RoleStateCaretaker rsc = new RoleStateCaretaker();

            rsc.RoleMemento = gr.SaveState();

            gr.Fight();
            gr.StateDisplay();

            gr.RecoveryState(rsc.RoleMemento);
            gr.StateDisplay();

            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            //备忘录
            Originator o = new Originator();

            o.State = "On";
            o.Show();

            Caretaker c = new Caretaker();

            c.Memento = o.CreateMemento();

            o.State = "Off";
            o.Show();

            o.SetMement(c.Memento);
            o.Show();



            GameRole gr = new GameRole();

            gr.InitState();
            gr.DisplayInfo();
            RoleCaretaker roletaker = new RoleCaretaker();

            roletaker.Rolememento = gr.CreateRoleMemento();

            gr.Over();
            gr.DisplayInfo();

            gr.RecoveryRoleMemento(roletaker.Rolememento);
            gr.DisplayInfo();


            Console.Read();
        }