Esempio n. 1
0
        public static void Show()
        {
            var service = new CustomerService();
            var command = new AddCustomerCommand(service);
            var button  = new Button(command);

            button.Click();

            var compositeCommand = new CompositeCommand();

            compositeCommand.Add(new ResizeCommand());
            compositeCommand.Add(new BlackAndWhiteCommand());
            compositeCommand.Execute();

            var history  = new History();
            var document = new HtmlDocument();

            document.Content = "Hello World";
            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();
            Console.WriteLine(document.Content);
            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();
            Console.WriteLine(document.Content);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var invoker = new Invoke();
            var text    = new MyText();

            text.WriteNewLine("Hi I am Ahmed \n");
            text.WriteNewLine("Hello This is a mistake \n");
            text.Print();
            var undoCommand = new UndoCommand(text);
            var redoCommand = new RedoCommand(text);

            invoker.SetCommand(undoCommand);
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Undo Completed");
            Console.WriteLine("==============================================");
            text.Print();
            text.WriteNewLine("Hell I now write good \n");
            text.WriteNewLine("Let's complete our work \n");
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Undo Completed");
            Console.WriteLine("==============================================");
            text.Print();
            invoker.SetCommand(redoCommand);
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Redo Completed");
            Console.WriteLine("==============================================");
            text.Print();
        }
 void Start()
 {
     buttonW     = new moveForward();
     buttonA     = new moveLeft();
     buttonS     = new moveBack();
     buttonD     = new moveRight();
     buttonR     = new UndoCommand();
     buttonSpace = new jumpCommand();
 }
Esempio n. 4
0
        // Use this for initialization
        void Start()
        {
            buttonW = new MoveForward();
            buttonA = new MoveLeft();
            buttonS = new MoveReverse();
            buttonD = new MoveRight();
            buttonB = new DoNothing();
            buttonZ = new UndoCommand();
            buttonR = new ReplayCommand();

            boxStartPos = boxTrans.position;
        }
Esempio n. 5
0
        void Start()
        {
            //Bind keys with commands
            buttonSeed              = new PlantSeedCommand();
            buttonTree              = new PlantTreeCommand();
            buttonTreeHoneyComb     = new PlantTreeHoneyCombCommand();
            buttonOpenNoticeMessage = new OpenNoticeMessage();
            buttonUndo              = new UndoCommand();
            //buttonR = new ReplayCommand();

            //boxStartPos = boxTrans.position;
        }
        static void Main(string[] args)
        {
            Document document = new Document();
            ICommand displayCmd = new DisplayCommand(document);
            ICommand redoCmd = new RedoCommand(document);
            ICommand undoCmd = new UndoCommand(document);

            Invoker invoker = new Invoker(displayCmd, redoCmd, undoCmd);
            invoker.Display();
            invoker.Redo();
            invoker.Undo();
        }
        static void Main(string[] args)
        {
            Document document   = new Document();
            ICommand displayCmd = new DisplayCommand(document);
            ICommand redoCmd    = new RedoCommand(document);
            ICommand undoCmd    = new UndoCommand(document);

            Invoker invoker = new Invoker(displayCmd, redoCmd, undoCmd);

            invoker.Display();
            invoker.Redo();
            invoker.Undo();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var videoEditor = new VideoEditor();
            var history     = new History();


            var setTextCommand = new LabelCommand("label", history, videoEditor);

            setTextCommand.execute();
            Console.WriteLine("Text: " + videoEditor);

            setTextCommand = new LabelCommand("New Label", history, videoEditor);
            setTextCommand.execute();
            Console.WriteLine("Text: " + videoEditor);


            var setContrastCommand = new ContrastCommand(100.65f, history, videoEditor);

            setContrastCommand.execute();
            Console.WriteLine("Contrast: " + videoEditor);

            setContrastCommand = new ContrastCommand(1.05f, history, videoEditor);
            setContrastCommand.execute();
            Console.WriteLine("Contrast: " + videoEditor);


            var undoCommand = new UndoCommand(history);

            undoCommand.execute();
            Console.WriteLine("Undo: " + videoEditor);

            undoCommand.execute();
            Console.WriteLine("Undo: " + videoEditor);

            undoCommand.execute();
            Console.WriteLine("Undo: " + videoEditor);

            Console.ReadLine();
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            //1、命令行模式的根本目的在于将“行为的请求者”和“行为的实现者”解耦;实现手段:“将行为抽象为对象”

            Document        doc    = new Document();
            DocumentCommand discmd = new DisplayCommand(doc);
            DocumentCommand undcmd = new UndoCommand(doc);
            DocumentCommand redcmd = new RedoCommand(doc);

            DocumentInvoker invoker = new DocumentInvoker(discmd, undcmd, redcmd);

            invoker.Display();
            invoker.Undo();
            invoker.Redo();



            PatrickLiuAndWife liuAndLai = new PatrickLiuAndWife();             //命令接受者
            Command           command   = new MakeDumplingsCommand(liuAndLai); //命令
            PaPaInvoker       papa      = new PaPaInvoker(command);            //命令请求者

            papa.ExecuteCommand();
            Console.ReadKey();
        }