Пример #1
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;
        }
Пример #2
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);
        }
Пример #3
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();
        }