Beispiel #1
0
 //悔棋
 public static void Undo(Chessman chess, int i)
 {
     Console.WriteLine("******悔棋******");
     index--;
     chess.Restore(mc.GetMemento(i - 1));       //撤销到上一个备忘录
     Console.WriteLine("棋子{0}当前位置为:第{1}行第{2}列。", chess.Label, chess.X, chess.Y);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            /*
             * Originator ori = new Originator("状态(1)");
             * Console.WriteLine(ori.GetState());
             *
             * Caretaker ct = new Caretaker();
             * ct.SetMemento(ori.CreateMemento());
             *
             * ori.SetState("状态(2)");
             * Console.WriteLine(ori.GetState());
             *
             * ori.RestoreMemento(ct.GetMemento());
             * Console.WriteLine(ori.GetState());
             */
            MementoCaretaker mc    = new MementoCaretaker();
            Chessman         chess = new Chessman("车", 1, 1);

            Display(chess);
            mc.SetMemento(chess.Save());         //保存状态
            chess.Y = 4;
            Display(chess);
            mc.SetMemento(chess.Save());         //保存状态
            Display(chess);
            chess.X = 5;
            Display(chess);
            Console.WriteLine("******悔棋******");
            chess.Restore(mc.GetMemento());         //恢复状态
            Display(chess);

            Console.Read();
        }
        static void Main(string[] args)
        {
            MementoCaretaker mc    = new MementoCaretaker();
            Chessman         chess = new Chessman("车", 1, 1);

            Display(chess);
            mc.SetMemento(chess.Save());         //保存状态
            chess.Y = 4;
            Display(chess);
            mc.SetMemento(chess.Save());         //保存状态
            Display(chess);
            chess.X = 5;
            Display(chess);
            Console.WriteLine("******悔棋******");
            chess.Restore(mc.GetMemento());         //恢复状态
            Display(chess);

            Console.Read();
        }