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);
        }
Ejemplo n.º 2
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);
        }