예제 #1
0
        static void RemoteControlTestMacro()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light                 livingRoomLight    = new Light("Living Room");
            CeilingFan            ceilingFan         = new CeilingFan("Living Room");
            Stereo                stereo             = new Stereo("Living Room");
            LightOnCommand        livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand       livingRoomLightOff = new LightOffCommand(livingRoomLight);
            CeilingFanHighCommand ceilingFanOn       = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff      = new CeilingFanOffCommand(ceilingFan);
            StereoOnWithCdCommand stereoOnWithCd     = new StereoOnWithCdCommand(stereo);
            StereoOffCommand      stereoOff          = new StereoOffCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, ceilingFanOn, stereoOnWithCd };
            ICommand[] partyOff = { livingRoomLightOff, ceilingFanOff, stereoOff };

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

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

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

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
        }
예제 #2
0
        public void Run()
        {
            RemoteControl rc = new RemoteControl();
            Light         livingRoomLight   = new Light("Living Room");
            Light         kitchenLight      = new Light("Kitchen");
            CeilingFan    kitchenCeilingFan = new CeilingFan("Kitchen");
            GarageDoor    garageDoor        = new GarageDoor();
            Stereo        stereo            = new Stereo("Living room");

            rc.SetCommand(0, new LightOnCommand(livingRoomLight), new LightOffCommand(livingRoomLight));
            rc.SetCommand(1, new LightOnCommand(kitchenLight), new LightOffCommand(kitchenLight));
            rc.SetCommand(2, new CeilingFanOnCommand(kitchenCeilingFan), new CeilingFanOffCommand(kitchenCeilingFan));
            rc.SetCommand(3, new StereoOnWithCDCommand(stereo), new StereoOffCommand(stereo));
            rc.SetCommand(4, new GarageDoorUpCommand(garageDoor), new GarageDoorDownCommand(garageDoor));

            Console.WriteLine(rc);
            Console.WriteLine();

            rc.OnButtonPushed(0);
            rc.OffButtonPushed(0);
            rc.OnButtonPushed(1);
            rc.OffButtonPushed(1);
            rc.OnButtonPushed(2);
            rc.OffButtonPushed(2);
            rc.OnButtonPushed(3);
            rc.OffButtonPushed(3);
            rc.OnButtonPushed(4);
            rc.OffButtonPushed(4);
        }
        private static void Main(string[] args)
        {
            RemoteControl remote = new RemoteControl();

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

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

            // fan commands
            CeilingFanOnOrChangeSpeedCommand ceilingFanOn  = new CeilingFanOnOrChangeSpeedCommand(ceilingFan);
            CeilingFanOffCommand             ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            // garage commands
            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garageDoor);

            // stereo commands
            StereoOnToCDCommand stereoOn  = new StereoOnToCDCommand(stereo);
            StereoOffCommand    stereoOff = new StereoOffCommand(stereo);

            // assign commands to slots
            remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remote.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remote.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remote.SetCommand(3, stereoOn, stereoOff);

            // print current remote state
            Console.WriteLine(remote);

            // test button presses
            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            remote.OffButtonWasPushed(2);
            remote.OnButtonWasPushed(3);
            remote.OffButtonWasPushed(3);
        }
예제 #4
0
        static void RemoteControlTest()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor();
            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);

            CeilingFanHighCommand ceilingFanOn  = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCd, stereoOff);
            remoteControl.SetCommand(4, garageDoorUp, garageDoorDown);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.UndoButtonWasPushed();
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.OnButtonWasPushed(4);
            remoteControl.OffButtonWasPushed(4);
        }
예제 #5
0
        public static void Main(string[] args)
        {
            var remoteControl = new Invokers.RemoteControl();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("Front");
            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);

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

            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

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

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);
            remoteControl.SetCommand(4, garageDoorUp, garageDoorDown);

            Console.WriteLine(remoteControl);

            // we can possibly have enums for those values, like 0 is for such and such, and so on
            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OffButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.OnButtonWasPushed(4);
            remoteControl.OffButtonWasPushed(4);
        }
예제 #6
0
        public static void Main(string[] args)
        {
            var remoteControl = new Invokers.RemoteControl();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("");
            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);

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

            GarageDoorUpCommand   garageDoorUp   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

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

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            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.ReadKey();
        }
        static void Main(string[] args)
        {
            var remoteControl = new Controllers.RemoteControl();

            var livingRoonLight = 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(livingRoonLight);
            var livingRoomLightOff = new LightOffCommand(livingRoonLight);
            var kitchenLightOn     = new LightOnCommand(kitchenLight);
            var kitchenLightOff    = new LightOffCommand(kitchenLight);

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

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

            var stereoOnWithCd = new StereoOnWithCdCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCd, stereoOff);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPressed(0);
            remoteControl.OffButtonWasPressed(0);
            remoteControl.OnButtonWasPressed(1);
            remoteControl.OffButtonWasPressed(1);
            remoteControl.OnButtonWasPressed(2);
            remoteControl.OffButtonWasPressed(2);
            remoteControl.OnButtonWasPressed(3);
            remoteControl.OffButtonWasPressed(3);

            Console.ReadLine();
        }
예제 #8
0
        static void Main(string[] args)
        {
            var remoteControl = new Controllers.RemoteControl();

            var livingRoonLight = new Light("Living Room");
            var television      = new Television("Living Room");
            var stereo          = new Stereo("Living Room");
            var hotTub          = new HotTub();

            var lightOn  = new LightOnCommand(livingRoonLight);
            var lightOff = new LightOffCommand(livingRoonLight);

            var televisionOn  = new TelevisionOnCommand(television);
            var televisionOff = new TelevisionOffCommand(television);

            var stereoOn  = new StereoOnCommand(stereo);
            var stereoOff = new StereoOffCommand(stereo);

            var hotTubOn  = new HotTubOnCommand(hotTub);
            var hotTubOff = new HotTubOffCommand(hotTub);

            var partyOn  = new ICommand[] { lightOn, stereoOn, televisionOn, hotTubOn };
            var partyOff = new ICommand[] { lightOff, stereoOff, televisionOff, hotTubOff };

            var partyMacroOn  = new MacroCommand(partyOn);
            var partyMacroOff = new MacroCommand(partyOff);

            remoteControl.SetCommand(0, partyMacroOn, partyMacroOff);

            Console.WriteLine(remoteControl);
            Console.WriteLine("----------Push Macro On----------");
            remoteControl.OnButtonWasPressed(0);
            Console.WriteLine("----------Push Macro Off---------");
            remoteControl.OffButtonWasPressed(0);

            Console.ReadLine();
        }
예제 #9
0
 public StereoOnToCDCommand(Stereo stereo)
 {
     this.stereo = stereo;
 }
예제 #10
0
        static void Main(string[] args)
        {
            SimpleRemoteControl control = new SimpleRemoteControl();

            // Объекты
            Garage     garage     = new Garage();
            Stereo     stereo     = new Stereo();
            CeilingFan ceilingFan = new CeilingFan("BedRoom");

            // Команды над объектами
            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garage);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage);

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

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

            // Запоминаем кнопки на пульте
            control.SetCommands(0, garageDoorOpen, garageDoorClose);
            control.SetCommands(1, stereoOnWithCD, stereoOff);
            control.SetCommands(2, ceilingFanMedium, ceilingFanOff);
            control.SetCommands(3, ceilingFanHigh, ceilingFanOff);

            control.OnButtonWasPressed(0);
            Thread.Sleep(1000);
            control.OnButtonWasPressed(1);
            Console.WriteLine("Играет музыка");
            Thread.Sleep(2500);
            control.undoButtonWasPushed();
            Thread.Sleep(1000);
            control.OffButtonWasPressed(0);
            Thread.Sleep(1000);
            control.OnButtonWasPressed(2);
            Thread.Sleep(1000);
            control.OffButtonWasPressed(2);
            Thread.Sleep(1000);
            control.undoButtonWasPushed();
            Thread.Sleep(1000);
            control.OnButtonWasPressed(3);
            Thread.Sleep(1000);
            control.OffButtonWasPressed(3);
            Thread.Sleep(1000);

            Console.WriteLine("---Часть 3---");
            Light           light    = new Light();
            LightOnCommand  lightOn  = new LightOnCommand(light);
            LightOffCommand lightOff = new LightOffCommand(light);

            ICommand[] _partyOn  = { garageDoorOpen, lightOn, stereoOnWithCD };
            ICommand[] _partyOff = { garageDoorClose, lightOff, stereoOff };

            MacroCommand macroCommandOn  = new MacroCommand(_partyOn);
            MacroCommand macroCommandOff = new MacroCommand(_partyOff);

            control.SetCommands(4, macroCommandOn, macroCommandOff);
            control.OnButtonWasPressed(4);
            Console.WriteLine("Вырубание");
            control.OffButtonWasPressed(4);
        }
 public StereoOffCommand(Stereo stereo)
 {
     this.stereo = stereo;
 }