예제 #1
0
        public static void ShowDemo()
        {
            Console.WriteLine("测试备忘录模式 --- 象棋的例子");

            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);
        }
예제 #2
0
        public static void ShowDemo()
        {
            Console.WriteLine("测试备忘录模式 --- 象棋的例子");

            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);
        }