コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// This is just to try passing back in an invalid memento.
        /// </summary>
        public void BadExecute()
        {
            Console.WriteLine("\nBad Execute!\n");
            ConstraintSolver solver = ConstraintSolver.Instance();

            solver.ChangeState();

            // Creating an object that is NOT a memento and storing it in the memento slot!
            object graphic = new Graphic();

            _state = graphic;
        }
コード例 #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();
        }
コード例 #4
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();
        }