public static void Load()
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            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);

            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(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.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            Console.WriteLine(remoteControl);

            for (int i = 0; i < 4; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
            }
        }
Exemple #2
0
        private static void Main()
        {
            var remoteControl = new RemoteControl();

            var light      = new Light("Living Room");
            var stereo     = new Stereo("Living Room");
            var ceilingFan = new CeilingFan("Living Room");

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

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

            var fanOn  = new CeilingFanOnCommand(ceilingFan);
            var fanOff = new CeilingFanOffCommand(ceilingFan);

            var partyOnMacro  = new MacroCommand(new ICommand[] { lightOn, stereoOnWithCd, fanOn });
            var partyOffMacro = new MacroCommand(new ICommand[] { lightOff, stereoOff, fanOff });

            remoteControl.SetCommand(0, lightOn, lightOff);
            remoteControl.SetCommand(1, stereoOnWithCd, stereoOff);
            remoteControl.SetCommand(2, fanOn, fanOff);
            remoteControl.SetCommand(3, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            remoteControl.PressOnButton(0);
            remoteControl.PressOffButton(0);
            remoteControl.PressUndoButton();

            Console.WriteLine("--- Pushing Macro On ---");
            remoteControl.PressOnButton(3);
            Console.WriteLine("--- Pushing Macro Off ---");
            remoteControl.PressOffButton(3);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      light      = new Light();
            Hottub     hottub     = new Hottub();
            GarageDoor garagedoor = new GarageDoor();
            CeilingFan ceilingfan = new CeilingFan();
            Stereo     stereo     = new Stereo();

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

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

            HottubOnCommand  hottubOn  = new HottubOnCommand(hottub);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            LightOnCommand  lightOn  = new LightOnCommand(light);
            LightOffCommand lightOff = new LightOffCommand(light);

            LivingroomLightOnCommand  livingRoomOn  = new LivingroomLightOnCommand(light);
            LivingroomLightOffCommand livingRoomOff = new LivingroomLightOffCommand(light);

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

            remoteControl.setCommand(0, ceilingFanOn, ceilingFanOff);
            remoteControl.setCommand(1, garageDoorUp, garageDoorDown);
            remoteControl.setCommand(2, hottubOn, hottubOff);
            remoteControl.setCommand(3, lightOn, lightOff);
            remoteControl.setCommand(4, livingRoomOn, livingRoomOff);
            remoteControl.setCommand(5, stereoOn, stereoOff);

            Console.WriteLine(remoteControl.toString());

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            remoteControl.offButtonWasPushed(4);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(5);
            remoteControl.offButtonWasPushed(5);
            remoteControl.undoButtonWasPushed();
        }
        public static void Main()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      livingRoomLight = new Light("Living room");
            Light      kitchenLight    = new Light("Kitchen Light");
            CeilingFan ceilingFan      = new CeilingFan("Living room");
            GarageDoor garageDoor      = new GarageDoor();
            Stereo     stereo          = new Stereo("Living room");
            TV         tv     = new TV("Living room");
            Hottub     hottub = new Hottub();

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            LightOnCommand  kitchenLightOn  = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

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

            GarageDoorOpenCommand  garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor);

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

            TVOnCommand  tvOn  = new TVOnCommand(tv);
            TVOffCommand tvOff = new TVOffCommand(tv);

            HottubOnCommand  hottubOn  = new HottubOnCommand(hottub);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            ICommand[] partyOn  = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff };

            //TODO: deal with the Macrocommand name
            Macrocommand partyOnMacro  = new Macrocommand(partyOn);
            Macrocommand partyOffMacro = new Macrocommand(partyOff);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);
            remoteControl.SetCommand(4, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPressed(0);
            remoteControl.OffButtonWasPressed(0);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(1);
            remoteControl.OffButtonWasPressed(1);
            remoteControl.OnButtonWasPressed(2);
            remoteControl.OffButtonWasPressed(2);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(3);
            remoteControl.OffButtonWasPressed(3);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(4);
            Console.WriteLine("Party is on!");
            remoteControl.OffButtonWasPressed(4);
            Console.WriteLine("Party is over");


            Console.ReadLine();
        }