示例#1
0
        public override void Execute()
        {
            Console.WriteLine("\nExecute!\n");
            ConstraintSolver solver = ConstraintSolver.Instance();

            // This is done just to show the current state.
            solver.Solve();

            // Create a memento
            // Acting as caretaker by storing it here
            _state = solver.CreateMemento();

            // Move graphic
            _target.Move(_delta);

            // Adjust constraints for movement
            solver.ChangeState();
            solver.Solve();
        }
示例#2
0
        /// <summary>
        /// This is just to try passing back an invalid memento.
        /// </summary>
        public void BadUnexecute()
        {
            Console.WriteLine("\nBad Undo!\n");
            ConstraintSolver solver = ConstraintSolver.Instance();

            // Restore bad state
            solver.SetMemento(_state);

            // Adjust constraints for reversed movement
            solver.Solve();
        }
示例#3
0
        public void Unexecute()
        {
            Console.WriteLine("\nUndo!\n");
            ConstraintSolver solver = ConstraintSolver.Instance();

            // Reverse graphic movement
            _delta.X = -_delta.X;
            _delta.Y = -_delta.Y;
            _target.Move(_delta);

            // Restore state
            solver.SetMemento(_state);

            // Adjust constraints for reversed movement
            solver.Solve();
        }