Ejemplo n.º 1
0
        public static void RunRemoteControlWithMacroCommand()
        {
            var light    = new Light();
            var lightOn  = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);

            var garageDoor      = new GarageDoor();
            var garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);

            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            var macroOnCommand  = new MacroCommand(new ICommand[] { lightOn, garageDoorOpen, stereoOnWithCD });
            var macroOffCommand = new MacroCommand(new ICommand[] { lightOff, garageDoorClose, stereoOff });

            var remote = new RemoteControl();

            remote.SetCommand(0, macroOnCommand, macroOffCommand);
            System.Console.WriteLine(remote);

            System.Console.WriteLine("--- Pushing Macro on ---");
            remote.OnButtonWasPressed(0);
            System.Console.WriteLine("--- Pushing Macro off ---");
            remote.OffButtonWasPressed(0);
        }
Ejemplo n.º 2
0
        public static void RunRemoteControl()
        {
            var remote          = new RemoteControl();
            var light           = new Light();
            var lightOn         = new LightOnCommand(light);
            var lightOff        = new LightOffCommand(light);
            var garageDoor      = new GarageDoor();
            var garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);
            var stereo          = new Stereo();
            var stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            var stereoOff       = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, garageDoorOpen, garageDoorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
        }
Ejemplo n.º 3
0
        public static void Main(String[] args)
        {
            // get the singleton only instance of the remote control
            RemoteControl remoteControl = RemoteControl.getInstance();

            // create all the receiver devices in their proper locations
            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("");
            Stereo <string, string, object, int> stereo = new Stereo <string, string, object, int>("Living Room");

            // create all the light command objects
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff    = new LightOffCommand(kitchenLight);

            // create the on and off commands for the ceiling fan
            CeilingFanOnCommand  ceilingFanOn  = new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            // create the up and down commands for the garage door
            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            // create the stereo on and off commands
            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            // load commands into the remote slots
            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);

            // print each remote slot and the command that it is assigned to
            Console.WriteLine(remoteControl);

            // push on and off button through each slot
            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OffButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            for (int i = 0; i < remoteControl.OnCommands.Length; i++)
            {
                remoteControl.UndoButtonWasPushed();
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Light           light    = new Light();
            LightOnCommand  lightOn  = new LightOnCommand(light);
            LightOffCommand lightOff = new LightOffCommand(light);

            Invoker invoker = new Invoker();


            Stereo stereo = new Stereo();

            StereoOnWithCDCommand stereoCommand = new StereoOnWithCDCommand(stereo);

            invoker.SetCommand(stereoCommand);
            invoker.RunCommand();


            invoker.SetCommand(lightOn);
            invoker.RunCommand();

            invoker.Undo();
            invoker.Undo();

            invoker.Redo();
            invoker.Redo();

            //************Running multiple commands at a go*****************

            /*
             * Light light = new Light();
             * Stereo stereo = new Stereo();
             *
             * LightOnCommand lightOn = new LightOnCommand(light);
             * LightOffCommand lightOff = new LightOffCommand(light);
             * StereoOnWithCDCommand stereoCommand = new StereoOnWithCDCommand(stereo);
             * StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo);
             *
             * Invoker invoker = new Invoker();
             *
             * invoker.SetCommand(lightOn);
             * invoker.SetCommand(lightOff);
             * invoker.SetCommand(stereoCommand);
             * invoker.SetCommand(stereoOffCommand);
             *
             * invoker.RunCommand();
             */
        }
Ejemplo n.º 5
0
        public static void RunRemoteControlWithUndo()
        {
            var remote         = new RemoteControlWithUndo();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, stereoOnWithCD, stereoOff);
            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.UndoButtonWasPressed();

            remote.OnButtonWasPressed(1);
            remote.UndoButtonWasPressed();
            remote.OffButtonWasPressed(1);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();


            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            GarageDoor garageDoor      = new GarageDoor();
            Stereo     stereo          = new Stereo("Living Room");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff    = new LightOffCommand(kitchenLight);

            GarageDoorOpenCommand  garageOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand  stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanLowCommand    ceilingFanLow    = new CeilingFanLowCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            Console.WriteLine(remoteControl.toString());

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();


            #region marco command
            Command[] partyOn  = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand  = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            #region Simple remote control test
            //Light light = new Light();
            //Command lightOn = new LightOnCommand(light);

            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //remote.SetCommand(lightOn);
            //remote.ButtonPressed();

            //GarageDoor door = new GarageDoor();
            //GaraDoorOpenCommand garageOpen = new GaraDoorOpenCommand(door);
            //remote.SetCommand(garageOpen);
            //remote.ButtonPressed();
            #endregion

            #region remote control
            //Light kitchenLight = new Light("kichen");
            //Light bedroomLight = new Light("bedroom");
            //Stereo parlorStereo = new Stereo("parlor");
            //Stereo washRommStereo = new Stereo("washroom");
            //GarageDoor garageDoor = new GarageDoor(string.Empty);

            //LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
            //LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);
            //StereoOnWithCDCommand parlorStereoOn = new StereoOnWithCDCommand(parlorStereo);
            //StereoOffCommand parloStereoOff = new StereoOffCommand(parlorStereo);
            //GaraDoorOpenCommand garageDoorOpen = new GaraDoorOpenCommand(garageDoor);
            //GaraDoorCloseCommand garageDoorClose = new GaraDoorCloseCommand(garageDoor);

            //RemoteControl remoteControl = new RemoteControl();
            //remoteControl.SetCommand(0, kitchenLightOn, kitchenLightOff);
            //remoteControl.SetCommand(1, parlorStereoOn, parloStereoOff);
            //remoteControl.SetCommand(2, garageDoorOpen, garageDoorClose);

            //remoteControl.OnButtonWasPushed(2);
            //remoteControl.OffButtonWasPushed(2);
            //remoteControl.OnButtonWasPushed(1);
            //remoteControl.OnButtonWasPushed(0);
            //remoteControl.OffButtonWasPushed(0);
            //remoteControl.OffButtonWasPushed(1);

            //remoteControl.OnButtonWasPushed(3);
            //remoteControl.OffButtonWasPushed(4);

            #endregion

            #region remote control with undo
            //Light livintRoomLight = new Light("livingroom");
            //LightOnCommand livingRoomOn = new LightOnCommand(livintRoomLight);
            //LightOffCommand livingRommOff = new LightOffCommand(livintRoomLight);
            //RemoteControlWithUndo remoteUndo = new RemoteControlWithUndo();
            //remoteUndo.SetCommand(0, livingRoomOn, livingRommOff);
            //remoteUndo.OnButtonWasPushed(0);
            //remoteUndo.OffButtonWasPushed(0);
            //Console.WriteLine(remoteUndo.ToString());
            //remoteUndo.UndoButtonWasPushed();
            //remoteUndo.OffButtonWasPushed(0);
            //remoteUndo.OnButtonWasPushed(0);
            //Console.WriteLine(remoteUndo.ToString());
            //remoteUndo.UndoButtonWasPushed();

            #endregion

            #region remote control with multiple undo states
            //RemoteControlWithUndo remote = new RemoteControlWithUndo();
            //CeilingFan fan = new CeilingFan("livingroom");
            //CeilingFanHighSpeedCommand ceilingFanHigh = new CeilingFanHighSpeedCommand(fan);
            //CeilingFanLowSpeedCommand ceilingFanLow = new CeilingFanLowSpeedCommand(fan);
            //CeilingFanOffSpeedCommand ceilingFanOff = new CeilingFanOffSpeedCommand(fan);
            //remote.SetCommand(0, ceilingFanHigh, ceilingFanOff);
            //remote.SetCommand(1, ceilingFanLow, ceilingFanOff);

            //remote.OnButtonWasPushed(0);
            //remote.OffButtonWasPushed(0);
            //Console.WriteLine(remote.ToString());
            //remote.UndoButtonWasPushed();

            //remote.OnButtonWasPushed(1);
            //Console.WriteLine(remote.ToString());
            //remote.UndoButtonWasPushed();
            #endregion

            #region remote control with macro commands
            RemoteControlWithUndo remote                     = new RemoteControlWithUndo();
            Light                        light               = new Light("livingroom");
            Stereo                       stero               = new Stereo("livingroom");
            CeilingFan                   fan                 = new CeilingFan("livingroom");
            LightOnCommand               livingLightOn       = new LightOnCommand(light);
            StereoOnWithCDCommand        livingStereoOn      = new StereoOnWithCDCommand(stero);
            CeilingFanMediumSpeedCommand livingCeilingMedium = new CeilingFanMediumSpeedCommand(fan);
            LightOffCommand              livingLightOff      = new LightOffCommand(light);
            StereoOffCommand             livingStereoOff     = new StereoOffCommand(stero);
            CeilingFanOffSpeedCommand    livingCeilingOff    = new CeilingFanOffSpeedCommand(fan);

            Command[]    macroOnCmd  = { livingLightOn, livingStereoOn, livingCeilingMedium };
            Command[]    macroOffCmd = { livingLightOff, livingStereoOff, livingCeilingOff };
            MacroCommand macroOn     = new MacroCommand(macroOnCmd);
            MacroCommand macroOff    = new MacroCommand(macroOffCmd);

            remote.SetCommand(0, macroOn, macroOff);

            Console.WriteLine(remote.ToString());
            remote.OnButtonWasPushed(0);
            Console.WriteLine("------push macro on-----");
            remote.OffButtonWasPushed(0);
            Console.WriteLine("------push macro off----");


            #endregion

            Console.Read();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            /*var remote = new SimpleRemoteControl();
             *
             * var light = new Light();
             * var garageDoor = new GarageDoor();
             *
             * var lightOnCommand = new LigthOnCommand(light);
             * var garageOpenCommand = new GarageDoorOpenCommand(garageDoor);
             *
             * remote.SetCommand(lightOnCommand);
             * remote.ButtonWasPressed();
             * remote.SetCommand(garageOpenCommand);
             * remote.ButtonWasPressed();*/

            var remoteControl = new RemoteControl();

            var livigRoomLight = new Light("Living Room");
            var kitchenLight   = new Light("Kitchen");
            var ceilingFan     = new CeilingFan("Living Room");
            var garageDoor     = new GarageDoor("");
            var stereo         = new Stereo("Living Room");

            var livingRoomLightOn  = new LightOnCommand(livigRoomLight);
            var livingRoomLightOff = new LightOffCommand(livigRoomLight);

            var kitchenRoomLightOn  = new LightOnCommand(kitchenLight);
            var kitchenRoomLightOff = new LightOffCommand(kitchenLight);

            var ceilingFanOn  = new CeilingFanOnCommand(ceilingFan);
            var ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            var garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            var garageDoorDown = new GarageDoorDownCommand(garageDoor);

            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenRoomLightOn, kitchenRoomLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OffButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);

            Console.WriteLine("-----------------------------------------------------");

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);

            remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            Console.WriteLine("-----------------------------------------------------");

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            Console.WriteLine("-----------------------------------------------------");

            var tv     = new TV("Living room");
            var hottub = new Hottub();

            var stereoOn = new StereoOnCommand(stereo);
            var tvOn     = new TVOnCommand(tv);
            var hottubOn = new HottubOnCommand(hottub);

            var tvOff     = new TVOffCommand(tv);
            var hottubOff = new HottubOffCommand(hottub);

            ICommand[] partyOn  = { livingRoomLightOn, stereoOn, tvOn, hottubOn };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff };

            var partyOnMacro  = new MacroCommand(partyOn);
            var partyOffMacro = new MacroCommand(partyOff);

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("---Pushing Macro On---");
            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine("---Pushing Macro Off---");
            remoteControl.OffButtonWasPushed(0);

            remoteControl.UndoButtonWasPushed();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            ////////SimpleRemoteControl remote = new SimpleRemoteControl();
            ////////ligth ligth = new ligth();
            ////////GarageDoor garageDoor = new GarageDoor();
            ////////LightOnCommand ligthon = new LightOnCommand(ligth);
            ////////GarageDoorOpenCommand garageOpen= new GarageDoorOpenCommand(garageDoor);
            ////////remote.setCommand(ligthon);
            ////////remote.buttonWasPressed();

            ////////remote.setCommand(garageOpen);
            ////////remote.buttonWasPressed();

            //////RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();
            //////ligth livingRoomLigth = new ligth("Living Room");
            //////ligth kitchenLight = new ligth("kitchen");
            //////GarageDoor garageDoor = new GarageDoor();
            //////stereo stereo = new stereo("Living Room");

            //////LightOnCommand livingRoomLigthOn = new LightOnCommand(livingRoomLigth);
            //////LightOffCommand livingRoomLigthOff = new LightOffCommand(livingRoomLigth);
            //////LightOnCommand KitchenLigthOn = new LightOnCommand(kitchenLight);
            //////LightOffCommand KitchenLigthOff = new LightOffCommand(kitchenLight);

            //////GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor);
            //////GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            //////StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            //////StereoOffCommand stereoOff = new StereoOffCommand(stereo);

            //////remoteControl.setCommand(0, livingRoomLigthOn, livingRoomLigthOff);
            //////remoteControl.setCommand(1, KitchenLigthOn, KitchenLigthOff);
            //////remoteControl.setCommand(2, stereoOnWithCD, stereoOff);

            //////Console.WriteLine(remoteControl.toString());

            //////remoteControl.onButtonWasPushed(0);
            //////remoteControl.offButtonWasPushed(0);
            //////remoteControl.onButtonWasPushed(1);
            //////remoteControl.offButtonWasPushed(1);
            //////remoteControl.onButtonWasPushed(2);
            //////remoteControl.offButtonWasPushed(2);
            //////Console.ReadLine();

            ////RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();
            ////ligth livingRoomLigth = new ligth("Living Room");

            ////LightOnCommand livingRoomLigthOn = new LightOnCommand(livingRoomLigth);
            ////LightOffCommand livingRoomLigthOff = new LightOffCommand(livingRoomLigth);

            ////remoteControl.setCommand(0, livingRoomLigthOn, livingRoomLigthOff);
            ////remoteControl.onButtonWasPushed(0);
            ////remoteControl.offButtonWasPushed(0);
            ////Console.WriteLine(remoteControl.toString());
            ////remoteControl.undoButtonWasPushed();
            ////remoteControl.offButtonWasPushed(0);
            ////remoteControl.onButtonWasPushed(0);
            ////Console.WriteLine(remoteControl.toString());
            ////remoteControl.undoButtonWasPushed();
            ////Console.ReadLine();
            //RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            //CeilingFan ceilingFan = new CeilingFan("Living Room");

            //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            //remoteControl.setCommand(0, ceilingFanMedium, ceilingFanOff);
            //remoteControl.setCommand(1, ceilingFanHigh, ceilingFanOff);

            //remoteControl.onButtonWasPushed(0);
            //remoteControl.offButtonWasPushed(0);
            //Console.WriteLine(remoteControl.toString());
            //remoteControl.undoButtonWasPushed();

            //remoteControl.onButtonWasPushed(1);
            //Console.WriteLine(remoteControl.toString());
            //remoteControl.undoButtonWasPushed();
            //Console.ReadLine();

            ligth light = new ligth("Living Room");
            stereo stereo = new stereo("Living Room");
            CeilingFan ceilingfan = new CeilingFan("living room");

            LightOnCommand ligthOn = new LightOnCommand(light);
            StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo);
            CeilingFanHighCommand CeilingfanOn = new CeilingFanHighCommand(ceilingfan);
            LightOffCommand ligthOff = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            CeilingFanOffCommand CeilingfanOff = new CeilingFanOffCommand(ceilingfan);

            command[] partyOn ={ligthOn,stereoOn,CeilingfanOn};
            command[] partyOff = { ligthOff, stereoOff, CeilingfanOff };

            MacroCommand partyOnMacro = new MacroCommand(partyOn);
            MacroCommand PartyOffMacro = new MacroCommand(partyOff);

            RemoteControlWithUndo remotecontrol = new RemoteControlWithUndo();

            remotecontrol.setCommand(0, partyOnMacro, PartyOffMacro);
            Console.WriteLine(remotecontrol.toString());
            Console.WriteLine("===Pushing Macro On ===");
            remotecontrol.onButtonWasPushed(0);
            Console.WriteLine("===Pushing Macro Off ===");
            remotecontrol.offButtonWasPushed(0);
            Console.WriteLine("===Pushing Macro undo ===");
            remotecontrol.undoButtonWasPushed();
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("-----------SimpleRemoteControl-------------");
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light          light       = new Light("Light");
            LightOnCommand lightOn     = new LightOnCommand(light);

            remote.setCommand(lightOn);
            remote.buttonWasPressed();

            Console.WriteLine("");

            RemoteControl remotControl = new RemoteControl();

            Light  livingRoomLight = new Light("Living Room");
            Light  kitchenLight    = new Light("Kitchen");
            Stereo stereo          = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            LightOnCommand  kitchenLightOn  = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

            StereoOnWithCDCommand StereoOnWithCDCommand = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      StereoOffCommand      = new StereoOffCommand(stereo);

            remotControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remotControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remotControl.setCommand(2, StereoOnWithCDCommand, StereoOffCommand);

            Console.WriteLine(remotControl.toString());

            remotControl.onButtonWasPushed(0);
            remotControl.offButtonWasPushed(0);
            remotControl.onButtonWasPushed(1);
            remotControl.offButtonWasPushed(1);
            remotControl.onButtonWasPushed(2);
            remotControl.offButtonWasPushed(2);


            Console.WriteLine("");

            RemoteControlWithUndo undoRemotControl = new RemoteControlWithUndo();

            Light livingRoomUndoLight = new Light("Living Room");

            LightOnCommand  livingRoomUndoLightOn  = new LightOnCommand(livingRoomUndoLight);
            LightOffCommand livingRoomUndoLightOff = new LightOffCommand(livingRoomUndoLight);

            undoRemotControl.setCommand(0, livingRoomUndoLightOn, livingRoomUndoLightOff);

            undoRemotControl.onButtonWasPushed(0);
            undoRemotControl.offButtonWasPushed(0);
            Console.WriteLine(undoRemotControl.toString());

            undoRemotControl.undoButtonWasPushed();
            undoRemotControl.onButtonWasPushed(0);
            undoRemotControl.offButtonWasPushed(0);
            Console.WriteLine(undoRemotControl.toString());

            undoRemotControl.undoButtonWasPushed();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();

            Light livingRoomLight = new Light("Living Room");
            Light kitchenLight = new Light("Kitchen");
            GarageDoor garageDoor = new GarageDoor();
            Stereo stereo = new Stereo("Living Room");
            CeilingFan ceilingFan = new CeilingFan("Living Room");

            LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

            GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

            CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            Console.WriteLine(remoteControl.toString());

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            #region marco command
            Command[] partyOn = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }