예제 #1
0
 //悔棋
 public static void Undo(Chessman chess, int i)
 {
     Console.WriteLine ("******悔棋******");
     index --;
     chess.restore(mc.getMemento(i-1)); //撤销到上一个备忘录
     Console.WriteLine("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }
예제 #2
0
 //撤销悔棋
 public static void Redo(Chessman chess, int i)
 {
     Console.WriteLine ("******撤销悔棋******");
     index ++;
     chess.restore(mc.getMemento(i+1)); //恢复到下一个备忘录
     Console.WriteLine("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }
예제 #3
0
 //撤销悔棋
 public static void Redo(Chessman chess, int i)
 {
     Console.WriteLine("******撤销悔棋******");
     index++;
     chess.restore(mc.getMemento(i + 1));   //恢复到下一个备忘录
     Console.WriteLine("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }
예제 #4
0
 //悔棋
 public static void Undo(Chessman chess, int i)
 {
     Console.WriteLine("******悔棋******");
     index--;
     chess.restore(mc.getMemento(i - 1));   //撤销到上一个备忘录
     Console.WriteLine("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }
예제 #5
0
        public static void ShowDemo()
        {
            Console.WriteLine("测试备忘录模式 --- 象棋的例子 (支持多次 UNDO 与 REDO) ");

            Chessman chess = new Chessman("车", 1, 1);
            Play(chess);

            chess.Y = 4;
            Play(chess);

            chess.X = 5;
            Play(chess);

            Undo(chess, index);
            Undo(chess, index);

            Redo(chess, index);
            Redo(chess, index);
        }
예제 #6
0
        public static void ShowDemo()
        {
            Console.WriteLine("测试备忘录模式 --- 象棋的例子 (支持多次 UNDO 与 REDO) ");

            Chessman chess = new Chessman("车", 1, 1);

            Play(chess);

            chess.Y = 4;
            Play(chess);

            chess.X = 5;
            Play(chess);

            Undo(chess, index);
            Undo(chess, index);

            Redo(chess, index);
            Redo(chess, index);
        }
예제 #7
0
 //下棋
 public static void Play(Chessman chess)
 {
     mc.setMemento(chess.save()); //保存备忘录
     index ++;
     Console.WriteLine ("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }
예제 #8
0
 //下棋
 public static void Play(Chessman chess)
 {
     mc.setMemento(chess.save());     //保存备忘录
     index++;
     Console.WriteLine("棋子" + chess.Label + "当前位置为:" + "第" + chess.X + "行" + "第" + chess.Y + "列。");
 }