Пример #1
0
        static void Main(string[] args)
        {
            //Existing stuff in the house
            Light          light          = new Light();
            AirConditioner airConditioner = new AirConditioner();

            // Create the On Commands
            LightOn          turnOnLight = new LightOn(light);
            AirConditionerOn turnOnAC    = new AirConditionerOn(airConditioner);

            // Create the Off Commands
            LightOff          turnOffLight = new LightOff(light);
            AirConditionerOff turnOffAC    = new AirConditionerOff(airConditioner);

            // Program remote controller
            RemoteController remote = new RemoteController();

            remote.InsertNewOnCommand(turnOnLight);
            remote.InsertNewOnCommand(turnOnAC);
            remote.InsertNewOffCommand(turnOffLight);
            remote.InsertNewOffCommand(turnOffAC);

            // Test buttons: Turn On the lights and AC
            remote.PressButtonOn(0);
            remote.PressButtonOn(1);

            // Test buttons: Turn Off the lights and AC
            remote.PressButtonOff(0);
            remote.PressButtonOff(1);


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Light  livingRoomLight = new Light("Living room light");
            Light  kitchenLight    = new Light("Kitchen light");
            Stereo loungeStereo    = new Stereo("Lounge stereo");

            LightOn   livingRoomLightOn  = new LightOn(livingRoomLight);
            LightOff  livingRoomLightOff = new LightOff(livingRoomLight);
            LightOn   kitchenLightOn     = new LightOn(kitchenLight);
            LightOff  kitchenLightOff    = new LightOff(kitchenLight);
            StereoOn  loungeStereoOn     = new StereoOn(loungeStereo);
            StereoOff loungeStereoOff    = new StereoOff(loungeStereo);

            RemoteControl remoteControl = new RemoteControl();

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, loungeStereoOn, loungeStereoOff);

            for (int i = 0; i < 7; i++)
            {
                remoteControl.OnButtonWasPushed(i);
            }

            for (int i = 0; i < 7; i++)
            {
                remoteControl.OffButtonWasPushed(i);
            }
        }
        static void Main(string[] args)
        {
            //Existing stuff in the house
            Light          bedRoomLights    = new Light();
            AirConditioner acForEntireHouse = new AirConditioner();

            //Create the ON commands
            LightOn          turnBedRoomLightsOn = new LightOn(bedRoomLights);
            AirConditionerOn turnOnAc            = new AirConditionerOn(acForEntireHouse);

            //Create the OFF commands
            LightOff          turnBedRoomLightOff = new LightOff(bedRoomLights);
            AirConditionerOff turnOffAc           = new AirConditionerOff(acForEntireHouse);

            //Add the ON to the remote
            RemoteController remote = new RemoteController();

            remote.InsertNewOnCommand(turnBedRoomLightsOn);
            remote.InsertNewOnCommand(turnOnAc);

            //Add the OFF to the remote
            remote.InsertNewOffCommand(turnBedRoomLightOff);
            remote.InsertNewOffCommand(turnOffAc);

            //Turn on the lights and AC
            remote.PressButtonOn(0);
            remote.PressButtonOn(1);

            //Turn off the lights and AC
            remote.PressButtonOff(0);
            remote.PressButtonOff(1);
        }
Пример #4
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl(3);

            // Creating objects to control
            Light garageLight     = new Light1("Garage Light");
            Light livingRoomLight = new Light2("Living Room Light");
            // Creating commands for objects to control
            LightOn  garageLightOnCommand      = new LightOn(garageLight);
            LightOff garageLightOffCommand     = new LightOff(garageLight);
            LightOn  livingRoomLightOnCommand  = new LightOn(livingRoomLight);
            LightOff livingRoomLightOffCommand = new LightOff(livingRoomLight);
            // Creating Collection for AllLightOff and AllLightOff commands.
            var LightsOn  = new Command[] { garageLightOnCommand, livingRoomLightOnCommand };
            var LightsOff = new Command[] { garageLightOffCommand, livingRoomLightOffCommand };

            // Creating Macro commands
            AllLightOn  houseLightsOnCommand  = new AllLightOn(LightsOn);
            AllLightOff houseLightsOffCommand = new AllLightOff(LightsOff);


            // Loading commands into the remoteControl
            remoteControl.SetCommand(0, garageLightOnCommand, garageLightOffCommand);
            remoteControl.SetCommand(1, livingRoomLightOnCommand, livingRoomLightOffCommand);
            remoteControl.SetCommand(2, houseLightsOnCommand, houseLightsOffCommand);
            // Simulating button clicks
            remoteControl.OnButtonPushed(0);
            remoteControl.OffButtonPushed(0);
            remoteControl.OnButtonPushed(1);
            remoteControl.OffButtonPushed(1);
            remoteControl.OnButtonPushed(2);
            remoteControl.OffButtonPushed(2);
        }
Пример #5
0
        static void Main(string[] args)
        {
            //  Existing stuff in the house


            Light bedRoomLights = new Light();


            AC acForTheHouse = new AC();


            // CREATE the On cmd

            LightOn trunbedRoomLightsOn = new LightOn(bedRoomLights);


            ACOn trunOnAC = new ACOn(acForTheHouse);


            // CREATE the off cmd

            LightOff trunbedRoomLightsOff = new LightOff(bedRoomLights);


            ACOff trunOffAC = new ACOff(acForTheHouse);



            // add the On  / off to the Remote

            RemoteController remote = new RemoteController();

            remote.InsertNewOnCommand(trunbedRoomLightsOn);
            remote.InsertNewOnCommand(trunOnAC);


            remote.InsertNewOffCommand(trunbedRoomLightsOff);
            remote.InsertNewOffCommand(trunOffAC);


            // turn on the Light and AC

            remote.PressButonOn(0);
            remote.PressButonOn(1);

            // turn off both
            remote.PressButonOff(0);
            remote.PressButonOff(1);
        }
        public Form1()
        {
            InitializeComponent();

            //ON commands (wrap receivers)
            LightOn turnBedRoomLightsOn = new LightOn(bedRoomLights);
            AirConditionerOn turnOnAC = new AirConditionerOn(acForHouse);

            //OFF commands
            LightOff turnBedRoomLightsOff = new LightOff(bedRoomLights);
            AirConditionerOff turnOffAC = new AirConditionerOff(acForHouse);

            //Add buttons to remote

            remote.InsertNewOnCommand(turnBedRoomLightsOn);
            remote.InsertNewOnCommand(turnOnAC);

            //OFF
            remote.InsertNewOffCommand(turnBedRoomLightsOff);
            remote.InsertNewOffCommand(turnOffAC);
        }