예제 #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
        private static readonly int NUMBEROFDEVICESTOBECONTROLLED = 3;  // For this example, the remote control will be able to control 3 devices.

        public MainWindow()
        {
            InitializeComponent();

            // Initialize the remote control.
            RemoteControl = new RemoteControl(NUMBEROFDEVICESTOBECONTROLLED);

            // Initialize the 'things' we want to control.
            Light      frontDoorLight    = new Light("Front door light");
            Light      kitchenLight      = new Light("Kitchen light");
            CeilingFan kitchenCeilingFan = new CeilingFan("Kitchen ceiling fan");

            // For each thing, we create two commands (ON and OFF).
            LightOnCommand       frontDoorLightOn     = new LightOnCommand(frontDoorLight);
            LightOffCommand      frontDoorLightOff    = new LightOffCommand(frontDoorLight);
            LightOnCommand       kitchenLightOn       = new LightOnCommand(kitchenLight);
            LightOffCommand      kitchenLightOff      = new LightOffCommand(kitchenLight);
            CeilingFanOnCommand  kitchenCeilingFanOn  = new CeilingFanOnCommand(kitchenCeilingFan);
            CeilingFanOffCommand kitchenCeilingFanOff = new CeilingFanOffCommand(kitchenCeilingFan);

            // Set each pair of ON-OFF commands to the buttons of the remote control.
            RemoteControl.SetCommand(0, frontDoorLightOn, frontDoorLightOff);
            RemoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            RemoteControl.SetCommand(2, kitchenCeilingFanOn, kitchenCeilingFanOff);


            device1Label.Content = frontDoorLight.Area;
            device2Label.Content = kitchenLight.Area;
            device3Label.Content = kitchenCeilingFan.Area;
        }
        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 RemoteControlTestCeilingFan()
        {
            RemoteControl remoteControl = new RemoteControl();

            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);
            remoteControl.UndoButtonWasPushed();

            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
        }
예제 #9
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);
        }