//撤销悔棋,恢复到下一个备忘录 static void Redo(Chessman chessman) { Console.WriteLine("******撤销悔棋******"); index++; chessman.Restore(mementoCaretaker.GetMemento(index)); chessman.Show(); }
static void Main(string[] args) { Chessman chess = new Chessman("車", 1, 1); Play(chess); chess.X = 4; Play(chess); chess.Y = 5; Play(chess); Undo(chess); Undo(chess); Redo(chess); Redo(chess); }
public static void Main(string[] args) { _chessman = new Chessman(new Point(1, 10)); _chessman.Position = new Point(2, 20); _chessman.Position = new Point(3, 30); _chessman.Position = new Point(4, 40); _chessman.Position = new Point(5, 50); _chessman.Position = new Point(9, 40); _chessman.Undo(1) .Undo(2) .Undo(1) .Redo() .Redo() .Redo() .Redo() .Redo() .Undo(6) .Undo(5) .Undo(4); Console.ReadKey(); }
//下棋,同时保存备忘录 static void Play(Chessman chessman) { mementoCaretaker.AddMemento(chessman.Save()); index++; chessman.Show(); }