示例#1
0
        static void Main(string[] args)
        {//儲存物件的重要狀態
         //維護物件的封裝


            Console.WriteLine("大戰boss前 初始狀態");

            GameRole role = new GameRole();

            role.GetInitState();
            role.StateDisplay();

            Console.WriteLine("保存進度");
            RoleStateTaker stateAdmin = new RoleStateTaker();

            stateAdmin.Memento = role.SaveState(); //不知道封裝那些資料

            Console.WriteLine("開始Fight!!");
            role.Fight();
            role.StateDisplay();

            Console.WriteLine("恢復原始狀態");
            role.RecoveryState(stateAdmin.Memento);
            role.StateDisplay();

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            //大战Boss前
            GameRole lixiaoyao = new GameRole();

            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            //保存进度
            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();

            stateAdmin.Memento = lixiaoyao.SaveState();

            //大战Boss时,损耗严重
            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            //恢复之前状态
            lixiaoyao.RecoveryState(stateAdmin.Memento);

            lixiaoyao.StateDisplay();


            Console.Read();
        }
示例#3
0
        static void Main(string[] args)
        {
            GameRole lixiaoyao = new GameRole();
            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            RoleStateCaretaker stateCaretaker = new RoleStateCaretaker {RoleStateMemento = lixiaoyao.SaveState()};

            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            lixiaoyao.RevcoveryState(stateCaretaker.RoleStateMemento);
            lixiaoyao.StateDisplay();

            Console.Read();
        }
示例#4
0
        static void Main(string[] args)
        {
            GameRole ben = new GameRole();

            ben.SetInitState();
            ben.StateDisplay();

            RoleStateCareTaker stateAdmin = new RoleStateCareTaker();

            stateAdmin.memento = ben.SaveState();

            ben.Fight();
            ben.StateDisplay();

            ben.RecoveryState(stateAdmin.memento);
            ben.StateDisplay();
        }
        static void Main(string[] args)
        {
            // 打王前
            GameRole character = new GameRole();

            character.GetInitState();
            character.StateDisplay();

            // 保存進度
            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();

            stateAdmin.Memento = character.SaveState();

            // 打王
            character.Fight();
            character.StateDisplay();

            // 讀取檔案
            character.RecoveryState(stateAdmin.Memento);

            character.StateDisplay();

            Console.WriteLine();

            Originator originator = new Originator();

            // 狀態初始屬性為On
            originator.State = "On";
            originator.Show();

            CareTaker careTaker = new CareTaker();

            // 保存狀態時,由於有了很好的封裝,可以隱藏Originator的實現細節
            careTaker.Memento = originator.CreateMemento();

            // 狀態屬性改為Off
            originator.State = "Off";
            originator.Show();

            // 恢復原初始狀態
            originator.SetMemento(careTaker.Memento);
            originator.Show();

            Console.ReadLine();
        }
示例#6
0
        static void Main(string[] args)
        {
            GameRole lixiaoyao = new GameRole();

            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            RoleStateCaretaker stateCaretaker = new RoleStateCaretaker();

            stateCaretaker.Memento = lixiaoyao.SaveState();

            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            lixiaoyao.RecoveryState(stateCaretaker.Memento);
            lixiaoyao.StateDisplay();

            Console.Read();
        }
示例#7
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();
        }
示例#8
0
        private static void Main(string[] args)
        {
            GameRole solider = new GameRole();

            solider.GetInitState();
            solider.StateDisplay();

            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();

            stateAdmin.Memento = solider.SaveState();

            solider.Fight();
            solider.StateDisplay();

            solider.RecoveryState(stateAdmin.Memento);

            solider.StateDisplay();
            Console.Read();
        }
示例#9
0
        static void Main(string[] args)
        {
            #region 基本用法(Basic.cs)
            Originator o = new Originator();
            //Originator初始状态,状态属性为“On”
            o.State = "On";
            o.Show();

            Caretaker c = new Caretaker();
            //保存状态时,由于有了很好的封装,可以隐藏Originator的实现细节
            c.Memento = o.CreateMemento();

            //Originator改变了状态属性为“Off”
            o.State = "Off";
            o.Show();

            //恢复原初始状态
            o.SetMemento(c.Memento);
            o.Show();
            #endregion

            #region 具体实例(Example.cs)
            //大战Boss前
            GameRole lixiaoyao = new GameRole();
            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            //保存进度
            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();
            stateAdmin.Memento = lixiaoyao.SaveState();

            //大战Boss时,损耗严重
            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            //恢复之前的状态
            lixiaoyao.RecoveryState(stateAdmin.Memento);
            lixiaoyao.StateDisplay();

            Console.Read();
            #endregion
        }
示例#10
0
        static void Main(string[] args)
        {
            #region 基本用法(Basic.cs)
            Originator o = new Originator();
            //Originator初始状态,状态属性为“On”
            o.State = "On";
            o.Show();

            Caretaker c = new Caretaker();
            //保存状态时,由于有了很好的封装,可以隐藏Originator的实现细节
            c.Memento = o.CreateMemento();

            //Originator改变了状态属性为“Off”
            o.State = "Off";
            o.Show();

            //恢复原初始状态
            o.SetMemento(c.Memento);
            o.Show();
            #endregion

            #region 具体实例(Example.cs)
            //大战Boss前
            GameRole lixiaoyao = new GameRole();
            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            //保存进度
            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();
            stateAdmin.Memento = lixiaoyao.SaveState();

            //大战Boss时,损耗严重
            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            //恢复之前的状态
            lixiaoyao.RecoveryState(stateAdmin.Memento);
            lixiaoyao.StateDisplay();

            Console.Read();
            #endregion
        }