// 下棋 public static void Play(Chessman chess) { // 保存备忘录 mementoCaretaker.SetMemento(chess.Save()); index++; Console.WriteLine("棋子 {0} 当前位置为 第 {1} 行 第 {2} 列", chess.Label, chess.X, chess.Y); }
public static void SingleRedoDemo() { MementoCaretaker mc = new MementoCaretaker(); Chessman chess = new Chessman("车", 1, 1); Display(chess); // 保存状态 mc.Memento = chess.Save(); chess.Y = 4; Display(chess); // 保存状态 mc.Memento = chess.Save(); Display(chess); chess.X = 5; Display(chess); Console.WriteLine("---------- Sorry,俺悔棋了 ---------"); // 恢复状态 chess.Restore(mc.Memento); Display(chess); }