Beispiel #1
0
 void Start()
 {
     forward = new MoveForwardCommand();
     stop    = new StopCommand();
     jump    = new JumpCommand();
     shoot   = new ShootCommand();
     slash   = new SlashCommand();
 }
Beispiel #2
0
        protected override void DefaultAction(CommandPattern command, TcpClient client)
        {
            IPEndPoint endPoint      = client.Client.RemoteEndPoint as IPEndPoint;
            IPAddress  ipaddress     = endPoint.Address;
            String     consoleNotice = String.Format("[{0}] Transmitted an unrecognised command: {1}.", ipaddress, command.Original);

            NLConsole.WriteLine(consoleNotice, ConsoleColor.Red);
            Byte[] response = Encoding.ASCII.GetBytes("UNRECOGNISED ACTION");
            client.GetStream().Write(response, 0, response.Length);
        }
Beispiel #3
0
        public static void InvokeConsoleCommand(String command)
        {
            CommandPattern commandPattern = CommandPattern.Create(command);
            Boolean        responded      = InvokeControllers(commandPattern);

            if (!responded)
            {
                WriteLine(UIStrings.UnrecognisedAction, ConsoleColor.White);
            }
        }
Beispiel #4
0
        public Boolean InvokeAction(CommandPattern command)
        {
            ActionDelegate action;

            ActionDictionary.TryGetValue(command.Command, out action);
            if (action != null)
            {
                action.Invoke(command.Parameters);
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        public Boolean InvokeAction(CommandPattern command, TcpClient client)
        {
            RemoteActionDelegate action;

            RemoteActionDictionary.TryGetValue(command.Command, out action);
            if (action != null)
            {
                action.Invoke(command.Parameters, client);
                return(true);
            }
            DefaultAction(command, client);
            return(false);
        }
Beispiel #6
0
        //Linker knop listener
        public void ButtonLeftPressed()
        {
            //mode selecteren
            if (mode == "setTimeNotation")
            {
                //als de optie 2 is, andere optie tonen
                if (option == 2)
                {
                    //Optie aanpassen
                    option = 1;

                    //Tekst weergeven
                    gui.displayText("24 uur notatie?");
                }
                else if (option == 1)
                {
                    //"
                    option = 2;
                    gui.displayText("12 uur notatie?");
                }
            }//mode selecteren
            else if (mode == "setColor")
            {//Per optie een antwoord geven
                if (option == 1)
                {
                    gui.displayText("Red");
                    this.option = 2;
                }
                else if (option == 2)
                {
                    gui.displayText("Green");
                    option = 3;
                }
                else if (option == 3)
                {
                    gui.displayText("Blue");
                    option = 1;
                }
            }//Stopwatch reset knop
            else if (mode == "setStopwatch")
            {
                //Command pattern gebruiken om de state in de memento op 0 te zetten
                CommandPattern command = new CommandPattern("saveState", time, gui, orig, 0);
                TimeEplapsed = 0;//tijd terug op 0 zetten

                //Gui updaten
                gui.updateStopwatch(TimeEplapsed);
            }
        }
Beispiel #7
0
        private static Boolean InvokeControllers(CommandPattern commandPattern)
        {
            Boolean responded = false;

            IController[] controllers = new IController[Controllers.Count];
            Controllers.CopyTo(controllers);
            foreach (IController subscriber in controllers)
            {
                Boolean response = subscriber.InvokeAction(commandPattern);
                if (response)
                {
                    responded = true;
                }
            }
            return(responded);
        }
        public static void Main(string[] args)
        {
            Pattern builderPattern = new BuilderPattern();

            builderPattern.Run();

            Pattern decoratorPattern = new DecoratorPattern();

            decoratorPattern.Run();

            Pattern singletonPattern = new SingletonPattern();

            singletonPattern.Run();

            Pattern commandPattern = new CommandPattern();

            commandPattern.Run();
        }
        public void Main_Pattern()
        {
            //创建型 5
            SingletonPattern.Used();
            SimpleFactory.Used();
            AbstructFactory.Used();
            BuilderParttern.Used();
            PrototypePattern.Used();

            //结构型 7
            AdapterPattern.Used();
            BridgePattern.Used();
            DecoratorPattern.Used();
            CompositePattern.Used();
            FlyweightPattern.Used();
            FacadePattern.Used();
            ProxyPattern.Used();

            //行为型 11
            ChainOfResponsibilityPattern.Used();
            CommandPattern.Used();
            InterpreterPattern.Used();
            //特殊类型 熔断器模式
        }
Beispiel #10
0
        private void Handle()
        {
            if (EndPoint == null)
            {
                _client.Close();
                return;
            }

            if (ServerConfiguration.BeepOnConnection)
            {
                Console.Beep(1000, 80);
                Console.Beep(1500, 80);
                Console.Beep(2000, 200);
            }

            IPAddress     ipaddress    = EndPoint.Address;
            NetworkStream clientStream = _client.GetStream();

            NLConsole.WriteLine(String.Format(UIStrings.ClientConnected, _controller.GetName(), ipaddress), _controller.ClientConnectedColor);

            int bytesRead = 0;

            Byte[]  messageBytes = new Byte[64];
            Boolean complete     = false;

            while (!ended)
            {
                try { bytesRead = clientStream.Read(messageBytes, 0, messageBytes.Length); }
                catch {
                    if (!ended)
                    {
                        NLConsole.WriteLine(String.Format(UIStrings.ClientTerminated, _controller.GetName(), ipaddress), _controller.ClientTerminatedColor);
                    }
                    break;
                }
                if (bytesRead == 0)
                {
                    complete = true;
                    break;
                }

                String         message = Encoding.ASCII.GetString(messageBytes, 0, bytesRead);
                CommandPattern command = CommandPattern.Create(message);
                _controller.InvokeAction(command, _client);
            }

            _client.Close();
            OnDeath.Invoke(this);

            if (complete)
            {
                NLConsole.WriteLine(String.Format(UIStrings.ClientDisconnected, _controller.GetName(), ipaddress), _controller.ClientDisconnectedColor);
            }

            if (ServerConfiguration.BeepOnDisconnection)
            {
                Console.Beep(2000, 80);
                Console.Beep(1500, 80);
                Console.Beep(1000, 200);
            }
        }
Beispiel #11
0
 protected abstract void DefaultAction(CommandPattern command, TcpClient client);
Beispiel #12
0
 protected override void DefaultAction(CommandPattern command, TcpClient client)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 protected override void DefaultAction(CommandPattern command, Socket client)
 {
 }
Beispiel #14
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine(_configuration["Logging:LogLevel:Default"]);

            IDesignPattern specificationPattern = new SpecificationPattern();

            specificationPattern.ExecuteSample();

            IDesignPattern factoryMethod = new FactoryMethodPattern();

            factoryMethod.ExecuteSample();

            IDesignPattern singletonPattern = new SingletonPattern();

            singletonPattern.ExecuteSample();

            IDesignPattern commandPattern = new CommandPattern();

            commandPattern.ExecuteSample();

            IDesignPattern chainOfResponsibilityPattern = new ChainOfResponsibilityPattern();

            chainOfResponsibilityPattern.ExecuteSample();

            IDesignPattern decoratorPattern = new DecoratorPattern();

            decoratorPattern.ExecuteSample();

            IDesignPattern strategyPattern = new StrategyPattern();

            strategyPattern.ExecuteSample();

            IDesignPattern abstractFactoryPattern = new AbstractFactoryPattern();

            abstractFactoryPattern.ExecuteSample();

            IDesignPattern compositePattern = new CompositePattern();

            compositePattern.ExecuteSample();

            IDesignPattern bridgePattern = new BridgePattern();

            bridgePattern.ExecuteSample();

            IDesignPattern observerPattern = new ObserverPattern();

            observerPattern.ExecuteSample();

            IDesignPattern statePattern = new StatePattern();

            statePattern.ExecuteSample();

            IDesignPattern mediatorPattern = new MediatorPattern();

            mediatorPattern.ExecuteSample();

            IDesignPattern visitorPattern = new VisitorPattern();

            visitorPattern.ExecuteSample();

            IDesignPattern momentoPattern = new MomentoPattern();

            momentoPattern.ExecuteSample();

            return(Task.CompletedTask);
        }
Beispiel #15
0
        //Rechter knop ingedrukt event handler, deze is vaak voor het menu
        public void ButtonRightPressed()
        {
            if (option < 1 || TimeEplapsed > 0)//zit in een andere mode
            {
                //Als de mode al op tijd staat komt de tijd notitie inbeeld
                if (mode == "time")
                {
                    //Mode aanpassen
                    mode = "setTimeNotation";

                    //Tijd op verborgen zetten
                    gui.timeVisible(false);

                    //Tekst weergeven
                    gui.displayText("Change timenotation?");
                }//mode aanpassen
                else if (mode == "setTimeNotation")
                {
                    //"
                    mode = "setColor";
                    gui.displayText("Change backgroundcolor?");
                }//mode aanpassen
                else if (mode == "setColor")
                {
                    //"
                    mode = "setStopwatch";
                    gui.displayText("Stopwatch mode?");
                }//mode aanpassen
                else if (mode == "setStopwatch")
                {
                    //Als er al een tijd beschikbaar is
                    if (TimeEplapsed > 0)
                    {
                        //De timer(klok) starten
                        time.startTimer();

                        //State opslaan in de memento mbv de command
                        CommandPattern command = new CommandPattern("saveState", time, gui, orig, TimeEplapsed);

                        //Tijd enzo resetten
                        TimeEplapsed = 0;
                        option       = 0;
                    }

                    //Mode terug zetten op tijd.
                    mode = "time";

                    //Display tekst leegmaken.
                    gui.displayText("");

                    //Tijd op zichtbaar zetten.
                    gui.timeVisible(true);
                }
            }//Als deze gewoon normaal
            else if (TimeEplapsed == 0 && mode == "setStopwatch" && option > 0)
            {
                //Tijd aanzetten
                time.startTimer();

                //Optie op 0 zetten
                option = 0;

                //Mode terugzetten naar tijd
                mode = "time";

                //Displaytekst leeg zetten
                gui.displayText("");

                //Tijd dingen zichbaar zetten
                gui.timeVisible(true);
            }
            Console.WriteLine("Mode: " + mode);
        }
Beispiel #16
0
        public void ButtonCenterPressed()
        {
            if (mode == "setTimeNotation" && option == 0)
            {
                option = 1;
                gui.displayText("24 uur notatie?");
            }
            else if (mode == "setTimeNotation" && option > 0)
            {
                if (option == 1)
                {
                    //24
                    CommandPattern command = new CommandPattern("24", time, gui);
                }
                else
                {
                    CommandPattern command = new CommandPattern("12", time, gui);
                }

                this.resetToTime();
            }
            else if (mode == "setColor" && option == 0)
            {
                option = 2;
                gui.displayText("Red");
            }
            else if (mode == "setColor" && option > 0)
            {
                if (option == 2)
                {
                    CommandPattern command = new CommandPattern("RED", time, gui);
                }
                else if (option == 3)
                {
                    CommandPattern command = new CommandPattern("Green", time, gui);
                }
                else if (option == 1)
                {
                    CommandPattern command = new CommandPattern("Blue", time, gui);
                }

                this.resetToTime();

                option = 0;
            }
            else if (mode == "setStopwatch" && option == 0)
            {
                time.pauzeTimer();
                gui.resetDisplay();

                try
                {
                    CommandPattern com = new CommandPattern("", time, gui, orig);
                    TimeEplapsed = com.getState(orig);
                    gui.updateStopwatch(TimeEplapsed);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                gui.displayText("");
                gui.timeVisible(true);
                gui.setTimeZone("0");

                option = 1;
            }
            else if (mode == "setStopwatch" && option == 1 || option == 2)
            {
                if (option == 1)
                {
                    //start
                    option = 2;//is gestart
                    Stopwatch.Start();
                }
                else if (option == 2)
                {
                    option = 1;//is gestopt
                    Stopwatch.Stop();
                }
            }
        }
Beispiel #17
0
 public TextTrigger(string eventText, CommandPattern behavior, Mode matchMode)
 {
     matchedText = eventText;
     _behavior = behavior;
     triggerMode = matchMode;
 }
Beispiel #18
0
 protected virtual void DefaultAction(CommandPattern command)
 {
 }