Example #1
0
        static void Main(string[] args)
        {
            RemoteControl RemoteControl = new RemoteControl();

            Light          light   = new Light("Living Room");
            LightOnCommand lightOn = new LightOnCommand(light);
            LightOfCommand lightOf = new LightOfCommand(light);

            CeilingFan ceiling = new CeilingFan("Living Room");

            CeilingFanLowcommand  fanLowcommand = new CeilingFanLowcommand(ceiling);
            CeilingFanHighCommand chigh         = new CeilingFanHighCommand(ceiling);

            CeilingFanOfcommand fanOfcommand = new CeilingFanOfcommand(ceiling);

            GarrageDoor            gd     = new GarrageDoor("Garrage");
            GarageDoorOpenCommand  gopen  = new GarageDoorOpenCommand(gd);
            GarageDoorCloseCommand gclose = new GarageDoorCloseCommand(gd);



            ICommand[] partyOn  = { lightOn, gopen, chigh };
            ICommand[] partyOff = { lightOf, gclose, fanLowcommand };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            RemoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(RemoteControl);
            Console.WriteLine("-----Pushing Macro On----");
            RemoteControl.OnButtonWasPressed(0);
            Console.WriteLine("--------- Pushing Macro Of------");
            RemoteControl.OffButtonWasPressed(0);
        }
Example #2
0
        static void Main(string[] args)
        {
            var remote = new SimpleRemoteControl();
            var light = new Light();
            var lightOn = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);

            var garageDoor = new GarageDoor();
            var garageDoorOpen = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);

            var stereo = new Stereo();
            var stereoOnWithCD = new StereoOnWithCdCommand(stereo);
            var stereoOn = new StereoOnCommand(stereo);
            var stereoOff = new StereoOffCommand(stereo);

            remote.SetCommand(lightOn);
            remote.ButtonWasPressed();
            remote.SetCommand(garageDoorOpen);
            remote.ButtonWasPressed();

            Console.WriteLine("\n-----Newer Universal Remote-----\n");

            var universalRemote = new RemoteControl();

            universalRemote.AddCommand("Light", lightOn, lightOff);
            universalRemote.AddCommand("GarageDoor", garageDoorOpen, garageDoorClose);
            universalRemote.AddCommand("Stereo", stereoOn, stereoOff);
            universalRemote.AddCommand("StereoWithCD", stereoOnWithCD, stereoOff);

            Console.WriteLine(universalRemote.ToString());

            Input(universalRemote);
        }
Example #3
0
        private static void Main()
        {
            var remote = new RemoteControl(3);


            var bike          = new Garage("Bike");
            var bikeDoorClose = new GarageDoorCloseCommand(bike);
            var bikeDoorOpen  = new GarageDoorOpenCommand(bike);

            var car          = new Garage("Car");
            var carDoorClose = new GarageDoorCloseCommand(car);
            var carDoorOpen  = new GarageDoorOpenCommand(car);

            var garageButton = new OnOffStruct
            {
                On  = bikeDoorOpen,
                Off = bikeDoorClose
            };

            remote[0] = garageButton;
            remote.PushOn(0);
            remote.PushUndo();
            remote.PushUndo();
            remote.PushOff(0);


            Console.WriteLine();
            var light = new Light("Hall");

            ICommand[] partyOn  = { new LightOffCommand(light), bikeDoorOpen, carDoorOpen };
            ICommand[] partyOff = { new LightOnCommand(light), bikeDoorClose, carDoorClose };


            remote[2] = new OnOffStruct {
                On = new MacroCommand(partyOn), Off = new MacroCommand(partyOff)
            };

            try
            {
                remote.PushOn(2);
                Console.WriteLine();
                remote.PushOff(2);
            }
            catch (Exception)
            {
                Console.WriteLine("Oops");
            }
        }
        static void Main(string[] args)
        {
            RemoteControl          remote      = new RemoteControl();
            Light                  light       = new Light();
            LightOnCommand         lightOn     = new LightOnCommand(light);
            LightOffCommand        lightOff    = new LightOffCommand(light);
            GarageDoor             garageDoor  = new GarageDoor();
            GarageDoorOpenCommand  garageOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, garageOpen, garageClose);

            Console.WriteLine(remote);

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(1);
            remote.UndoButtonWasPushed();

            CeilingFan              ceilingFan       = new CeilingFan("Living Room");
            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remote.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remote.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            Console.WriteLine(remote);
            remote.UndoButtonWasPushed();

            remote.OnButtonWasPushed(1);
            Console.WriteLine(remote);
            remote.UndoButtonWasPushed();

            Console.Read();
        }
Example #5
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();


            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            GarageDoor garageDoor      = new GarageDoor();
            Stereo     stereo          = new Stereo("Living Room");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff    = new LightOffCommand(kitchenLight);

            GarageDoorOpenCommand  garageOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand  stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanLowCommand    ceilingFanLow    = new CeilingFanLowCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            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(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();


            #region marco command
            Command[] partyOn  = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand  = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var simpleRemoteControl = new SimpleRemoteControl();
            var light          = new Light("Bedroom");
            var lightOnCommand = new LightOnCommand(light);

            simpleRemoteControl.SetCommand(lightOnCommand);
            simpleRemoteControl.ButtonWasPressed();

            var door = new GarageDoor("");
            var garageDoorOpenCommand = new GarageDoorOpenCommand(door);

            simpleRemoteControl.SetCommand(garageDoorOpenCommand);
            simpleRemoteControl.ButtonWasPressed();

            Console.WriteLine();

            var livingRoomLight = 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 livingRoomLightOnCommand  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight);
            var kitchenLightOnCommand     = new LightOnCommand(kitchenLight);
            var kitchenLightOffCommand    = new LightOffCommand(kitchenLight);

            var ceilingFanOnCommand  = new CeilingFanOnCommand(ceilingFan);
            var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);

            var garageDoorUpCommand   = new GarageDoorOpenCommand(garageDoor);
            var garageDoorDownCommand = new GarageDoorCloseCommand(garageDoor);

            var stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo);
            var stereoOffCommand      = new StereoOffCommand(stereo);

            var remote = new RemoteControl();

            remote.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            remote.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand);
            remote.SetCommand(2, ceilingFanOnCommand, ceilingFanOffCommand);
            remote.SetCommand(3, stereoOnWithCdCommand, stereoOffCommand);

            Console.WriteLine(remote.ToString());
            Console.WriteLine();
            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            remote.OffButtonWasPushed(2);
            remote.OnButtonWasPushed(3);
            remote.OffButtonWasPushed(3);

            Console.WriteLine();
            Console.WriteLine("------------ Remote with Undo ------------");

            var remoteWithUndo         = new RemoteControlWithUndo();
            var sunRoomLight           = new Light("Sun Room");
            var sunRoomLightOnCommand  = new LightOnCommand(sunRoomLight);
            var sunRoomLightOffCommand = new LightOffCommand(sunRoomLight);

            remoteWithUndo.SetCommand(0, sunRoomLightOnCommand, sunRoomLightOffCommand);

            remoteWithUndo.OnButtonWasPushed(0);
            remoteWithUndo.OffButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();
            remoteWithUndo.OffButtonWasPushed(0);
            remoteWithUndo.OnButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            Console.WriteLine();
            Console.WriteLine("------------ Ceiling Fan with Undo ------------");

            remoteWithUndo = new RemoteControlWithUndo();
            var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHighCommand   = new CeilingFanHighCommand(ceilingFan);

            ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);
            remoteWithUndo.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand);
            remoteWithUndo.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand);

            remoteWithUndo.OnButtonWasPushed(0);
            remoteWithUndo.OffButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            remoteWithUndo.OnButtonWasPushed(1);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            Console.WriteLine();
            Console.WriteLine("------------ Party Mode (Macro Commands) ------------");
            remoteWithUndo = new RemoteControlWithUndo();
            ICommand[] partyOn       = { livingRoomLightOnCommand, stereoOnWithCdCommand, ceilingFanMediumCommand };
            ICommand[] partyOff      = { livingRoomLightOffCommand, stereoOffCommand, ceilingFanOffCommand };
            var        partyOnMacro  = new MacroCommand(partyOn);
            var        partyOffMacro = new MacroCommand(partyOff);

            remoteWithUndo.SetCommand(0, partyOnMacro, partyOffMacro);
            remoteWithUndo.OnButtonWasPushed(0);
            Console.WriteLine();
            remoteWithUndo.OffButtonWasPushed(0);

            Console.ReadLine();
        }
Example #7
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();

            Light livingRoomLight = new Light("Living Room");
            Light kitchenLight = new Light("Kitchen");
            GarageDoor garageDoor = new GarageDoor();
            Stereo stereo = new Stereo("Living Room");
            CeilingFan ceilingFan = new CeilingFan("Living Room");

            LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

            GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

            CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            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(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            #region marco command
            Command[] partyOn = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }