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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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 }
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 }
static void Main(string[] args) { System.Console.WriteLine("开始游戏"); Game lixiaoyao = new Game(); lixiaoyao.InitState(); lixiaoyao.StateDisplay(); //保存进度 RoleStateCaretaker caretaker = new RoleStateCaretaker(); caretaker.Memento = lixiaoyao.SaveState(); //战斗 System.Console.WriteLine("开始战斗"); lixiaoyao.Fight(); lixiaoyao.StateDisplay(); System.Console.WriteLine("恢复进度中。。。"); //恢复值 lixiaoyao.RecoveryState(caretaker.Memento); lixiaoyao.StateDisplay(); }