コード例 #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);
        }
コード例 #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();
        }
コード例 #3
0
 void Start()
 {
     buttonW     = new moveForward();
     buttonA     = new moveLeft();
     buttonS     = new moveBack();
     buttonD     = new moveRight();
     buttonR     = new UndoCommand();
     buttonSpace = new jumpCommand();
 }
コード例 #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;
        }
コード例 #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;
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: chauhanKV/DesignPatterns
        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();
        }
コード例 #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();
        }