Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var remote = new SimpleRemoteControl();

            var kitchenLight = new Light("kitchen light");
            var livingLight  = new Light("living room light");
            var garageDoor   = new GarageDoor();
            var stereo       = new Stereo();

            var kitLightOnCommand  = new LightOnCommand(kitchenLight);
            var kitLightOffCommand = new LightOffCommand(kitchenLight);

            var lightOnCommand  = new LightOnCommand(livingLight);
            var lightOffCommand = new LightOffCommand(livingLight);

            var garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);

            var stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo);
            var stereoOffCommand      = new StereoOffCommand(stereo);

            var ceilingFan            = new CeilingFan("Ceiling fan");
            var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanLowCommand  = new CeilingFanLowCommand(ceilingFan);
            var ceilingFanOffCommand  = new CeilingFanOffCommand(ceilingFan);

            remote.SetCommand(0, lightOnCommand, lightOffCommand);
            remote.SetCommand(1, kitLightOnCommand, kitLightOffCommand);
            remote.SetCommand(2, garageDoorOpenCommand, garageDoorCloseCommand);
            remote.SetCommand(3, stereoOnWithCDCommand, stereoOffCommand);
            remote.SetCommand(4, ceilingFanHighCommand, ceilingFanOffCommand);
            remote.SetCommand(5, ceilingFanLowCommand, ceilingFanOffCommand);

            remote.OnButtonPressed(0);
            remote.OffButtonPressed(0);
            remote.OnButtonPressed(1);
            remote.OffButtonPressed(1);
            remote.OnButtonPressed(2);
            remote.OffButtonPressed(2);
            remote.OnButtonPressed(3);
            remote.OffButtonPressed(3);
            remote.OnButtonPressed(4);
            remote.OffButtonPressed(4);
            remote.UndoButtonPressed();
            remote.OnButtonPressed(5);
            remote.OffButtonPressed(5);
            remote.UndoButtonPressed();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();

            Light      livingRoomLight  = new Light("Living Romm");
            Light      kitchenRoomLight = new Light("kitchen Romm");
            GarageDoor garageDoor       = new GarageDoor("");
            CeilingFan ceilingFan       = new CeilingFan("Living Room");
            Stereo     stereo           = new Stereo("Living Room");

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

            LightOnCommand  kitchenRoomLightOn  = new LightOnCommand(kitchenRoomLight);
            LightOffCommand kitchenRoomLightOff = new LightOffCommand(kitchenRoomLight);

            CeilingFanHighCommand ceilingFanOn  = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCdCommand = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOffCommand      = new StereoOffCommand(stereo);

            remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remote.SetCommand(1, kitchenRoomLightOn, kitchenRoomLightOff);
            remote.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remote.SetCommand(3, stereoOnWithCdCommand, stereoOffCommand);

            Console.WriteLine(remote.ToString());

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);

            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);

            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);

            remote.OnButtonWasPressed(3);
            remote.OffButtonWasPressed(3);


            Console.ReadLine();
        }
        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);
            }
        }
        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 light = new Light("Hall");

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

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

            Console.WriteLine();

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

            remote.PushOn(1);
            remote.PushOn(2);
            Console.WriteLine();
            remote.PushOff(2);

            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main()
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            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.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.UndoButtonWasPressed();

            remote.SetCommand(1, garageOpen, garageClose);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        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();
        }