Пример #1
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();
        }