static void Main(string[] args)
        {
            Command c = new Command(new Receiver());

            Command.Execute();
            Command.Redo();
            Command.Undo();
            Command.Execute();
            Console.ReadKey();
        }
Exemple #2
0
        public override void Execute(Transform boxTrans, Command command)
        {
            List <Command> oldCommands = InputHandler.oldCommands;

            if (oldCommands.Count > 0)
            {
                Command latestCommand = oldCommands [oldCommands.Count - 1];

                latestCommand.Undo(boxTrans);
                oldCommands.RemoveAt(oldCommands.Count - 1);
            }
        }
        public override void Execute(Transform actorTransform, Command command)
        {
            Stack <Command> actorCommandStack = actorTransform.gameObject.GetComponent <InputHandler>().previousCommands;

            if (actorCommandStack.Count < 1)
            {
                return;
            }

            Command lastCommand = actorCommandStack.Pop();

            lastCommand?.Undo(actorTransform);
        }
Exemple #4
0
 public void UndoPreviousCommand()
 {
     if (_undoCommands.Count > 0)
     {
         Command previousCommand = _undoCommands.Pop();
         previousCommand.Undo();
         AddToRedo(previousCommand);
         Debug.Log("Undid the previous command");
     }
     else
     {
         Debug.Log("At the start of command list");
     }
 }
Exemple #5
0
        //Called when we press a key
        public override void Execute(Transform boxTrans, Command command)
        {
            List <Command> oldCommands = InputHandler.oldCommands;

            if (oldCommands.Count > 0)
            {
                Command latestCommand = oldCommands[oldCommands.Count - 1];

                //Move the box with this command
                latestCommand.Undo(boxTrans);

                //Remove the command from the list
                oldCommands.RemoveAt(oldCommands.Count - 1);
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Command Pattern Example");

            var shoppingCartRepository = new ShoppingCartRepository();
            var productRepository      = new ProductRepository();

            var product = productRepository.Find(1);

            var addToCartCommand = new AddToCartCommand(shoppingCartRepository,
                                                        productRepository,
                                                        product);

            var increaseQuantityCommand = new ChangeQuantityCommand(ChangeQuantityCommand.Operation.Increase,
                                                                    product,
                                                                    shoppingCartRepository,
                                                                    productRepository);

            var command = new Command();

            Console.WriteLine("Adding item to shopping cart...");
            command.Invoke(addToCartCommand);
            var addedLineItem = shoppingCartRepository.Get(product.Id);

            Console.WriteLine($"Item added to shopping cart : Name : {addedLineItem.Product.Name} Quantity : {addedLineItem.Quantity}");

            Console.WriteLine("Increasing quantity...");
            command.Invoke(increaseQuantityCommand);
            addedLineItem = shoppingCartRepository.Get(product.Id);
            Console.WriteLine($"Item added to shopping cart : Name : {addedLineItem.Product.Name} Quantity : {addedLineItem.Quantity}");

            Console.WriteLine("Increasing quantity...");
            command.Invoke(increaseQuantityCommand);
            addedLineItem = shoppingCartRepository.Get(product.Id);
            Console.WriteLine($"Item added to shopping cart : Name : {addedLineItem.Product.Name} Quantity : {addedLineItem.Quantity}");

            Console.WriteLine("Increasing quantity...");
            command.Invoke(increaseQuantityCommand);
            addedLineItem = shoppingCartRepository.Get(product.Id);
            Console.WriteLine($"Item added to shopping cart : Name : {addedLineItem.Product.Name} Quantity : {addedLineItem.Quantity}");

            PrintShoppingCart(shoppingCartRepository);

            Console.WriteLine("Undo all actions");
            command.Undo();

            PrintShoppingCart(shoppingCartRepository);
        }
        //Called when we press a key
        public override void Execute(GameObject boxTrans, Command command)
        {
            List <Command> oldCommands = InputHandler.oldCommands;

            if (oldCommands.Count > 0)
            {
                Debug.Log("Trying to undo");
                Command latestCommand = oldCommands[oldCommands.Count - 1];

                //Move the box with this command
                latestCommand.Undo(boxTrans);

                //Remove the command from the list
                oldCommands.RemoveAt(oldCommands.Count - 1);
            }
        }
Exemple #8
0
        // press key for calling function
        public override void Execute(Transform myObj, Command command)
        {
            // create and save commands list for each time press key to call function for undo
            List <Command> preCommand = CommandPattern.preCommand;

            if (preCommand.Count > 0)
            {
                // last command is the end of command list - 1 because last command should go back previous command
                Command latestCommand = preCommand[preCommand.Count - 1];

                // object goes to last command
                latestCommand.Undo(myObj);

                // after go back previous command and remove last command in the end of list
                preCommand.RemoveAt(preCommand.Count - 1);
            }
        }
Exemple #9
0
 public void UndoButtonWasPushed()
 {
     undoCommand.Undo();
 }
Exemple #10
0
 //take base class and overwrite function
 public override void Execute(GameObject gameObject, Command command)
 {
     //passing arguements
     command.Undo(gameObject, command);
 }
 public void UndoButtonPushed(int slot)
 {
     undoCommand.Undo();
 }
Exemple #12
0
 public void OnClickUndo()
 {
     lastCommond.Undo();
     lastCommond = new NoCommand();
 }