private static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Ventilador ventilador = new Ventilador("Sala"); VentiladorHighCommand highCommand = new VentiladorHighCommand(ventilador); VentiladorMediumCommand mediumCommand = new VentiladorMediumCommand(ventilador); VentiladorOffCommand offCommand = new VentiladorOffCommand(ventilador); remoteControl.SetCommand(0, mediumCommand, offCommand); remoteControl.SetCommand(1, highCommand, offCommand); remoteControl.OnButtonPushed(0); remoteControl.OffButtonPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonPushed(1); remoteControl.UndoButtonWasPushed(); Console.Write(remoteControl.ToString()); }
static void Main() { var tv = new CommandTv("Телевизор в гостиной"); var tv2 = new CommandTv("Телевизор в спальне"); var tv3 = new CommandTv("Телевизор на кухне"); var light = new CommandLight("Свет в гостиной"); var light2 = new CommandLight("Свет в спальне"); var light3 = new CommandLight("Свет на кухне"); var remoteControl = new RemoteControl(); remoteControl.AddDevice(1, tv); remoteControl.AddDevice(2, light); remoteControl.AddDevice(3, tv2); remoteControl.AddDevice(4, light2); remoteControl.AddDevice(5, tv3); remoteControl.AddDevice(6, light3); remoteControl.PrintMenu(); var input = Console.ReadLine(); while (input != "0") { if (input != null) { var button = Int32.Parse(input); remoteControl.RunCommand(button); } input = Console.ReadLine(); } }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); #region // //Light light = new Light(); //Light garageDoorLight = new Light(); //Stereo stereo = new Stereo(); //// //LightOnCommand lightOnCommand = new LightOnCommand(light); //GarageLightOnCommand garageLightOnCommand = new GarageLightOnCommand(garageDoorLight); //StereoOnWithCdCommand stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo); //LightOffCommand lightOffCommand = new LightOffCommand(light); //GarageLightOffCommand garageLightOffCommand = new GarageLightOffCommand(garageDoorLight); //StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); //// //remoteControl.SetCommand(0, lightOnCommand, lightOffCommand); //remoteControl.SetCommand(1, garageLightOnCommand, garageLightOffCommand); //remoteControl.SetCommand(2, stereoOnWithCdCommand, stereoOffCommand); //// //Console.WriteLine(remoteControl); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine(remoteControl); //remoteControl.UndoButtonWasPushed(); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(0); //Console.WriteLine(remoteControl); //remoteControl.UndoButtonWasPushed(); ////remoteControl.OnButtonWasPushed(1); ////remoteControl.OffButtonWasPushed(1); ////remoteControl.OnButtonWasPushed(2); ////remoteControl.OffButtonWasPushed(2); #endregion var ceilingFan = new CeilingFan(); var ceilingFanHight = new CeilingFanHightCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(1, ceilingFanHight, ceilingFanOff); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.ReadKey(true); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light livingRoomLight = new Light(); Stereo stereo = new Stereo(); CeilingFan ceilingFan = new CeilingFan("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); StereoOnCommand stereoOn = new StereoOnCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); Console.WriteLine(remote.ToString()); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, stereoOn, stereoOff); remote.SetCommand(2, ceilingFanHigh, ceilingFanOff); remote.SetCommand(3, ceilingFanMedium, ceilingFanOff); remote.SetCommand(4, ceilingFanLow, ceilingFanOff); Console.WriteLine(remote.ToString()); //remote.OnButtonWasPushed(0); //remote.OnButtonWasPushed(1); //remote.OffButtonWasPushed(0); //remote.OffButtonWasPushed(1); //remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(2); //remote.OnButtonWasPushed(3); //remote.UndoButtonWasPushed(); //remote.OffButtonWasPushed(2); //remote.UndoButtonWasPushed(); Command[] onCommands = { livingRoomLightOn, stereoOn, ceilingFanHigh }; MacroCommand macroCommandOn = new MacroCommand(onCommands); Command[] offCommands = { livingRoomLightOff, stereoOff, ceilingFanOff }; MacroCommand macroCommandOff = new MacroCommand(offCommands); remote.SetCommand(5, macroCommandOn, macroCommandOff); remote.OnButtonWasPushed(5); Console.WriteLine(); //remote.OffButtonWasPushed(5); remote.UndoButtonWasPushed(); }
//Avoid coupling the sender of a request to its receiver by giving more than one //object chance to handle the request. static void Main(string[] _) { var lamp = new Lamp(); var turnOff = new TurnOff(lamp); var turnOn = new TurnOn(lamp); var remote = new RemoteControl(); remote.Submit(turnOff); remote.Submit(turnOn); Console.ReadKey(); }
static void Main(string[] args) { IDevice bulb = new Bulb(); ICommand turnOn = new TurnOn(bulb); ICommand turnOff = new TurnOff(bulb); RemoteControl remote = new RemoteControl(); remote.submit(turnOn); remote.submit(turnOff); System.Console.ReadLine(); }
static void Main() { var bulb = new Bulb(); var turnOn = new TurnOn(bulb); var turnOff = new TurnOff(bulb); var remote = new RemoteControl(); remote.Submit(turnOn); remote.Submit(turnOff); Console.ReadLine(); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light light = new Light(); ICommand lightsOn = new LightOnCommand(light); ICommand lightsOff = new LightOffCommand(light); remote.SetCommand(lightsOn); remote.pressButton(); remote.SetCommand(lightsOff); remote.pressButton(); }
static void Main() { RemoteControl remote = new RemoteControl(); Lights lights = new Lights(); ICommand command1 = new TurnLightsOn(lights); ICommand command2 = new TurnLightsOff(lights); remote.SetButton(0, command1); remote.PressButton(0); remote.SetButton(0, command2); remote.PressButton(0); Console.ReadLine(); }
static void Main(string[] args) { Light light = new Light(); Command c1 = new CommandOff(light); Command c2 = new CommandOn(light); // RemoteControl remote = new RemoteControl(); remote.pressButton(c1); //remote.pressButton(c2); Console.ReadKey(); }
static void Main(string[] args) { var myGarage = new Garage("Huy Tran's Garage"); var openGarage = new GarageOpen(myGarage); var CloseGarage = new GarageClose(myGarage); var myRemote = new RemoteControl(); int choose; myRemote.Show(); choose = Int32.Parse(Console.ReadLine()); while (choose != 3) { switch (choose) { case 1: Console.ForegroundColor = ConsoleColor.Red; myRemote.Submit(openGarage); Console.ResetColor(); break; case 2: Console.ForegroundColor = ConsoleColor.Red; myRemote.Submit(CloseGarage); Console.ResetColor(); break; case 3: break; } if (choose == 3) { break; } Console.WriteLine(); myRemote.Show(); choose = Int32.Parse(Console.ReadLine()); } Console.WriteLine(); Console.ReadKey(); }
public void Undo() { RemoteControl remoteControl = new RemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); remoteControl.SetCommand(0, lightOn, lightOff); remoteControl.OnButtonPushed(0); remoteControl.OffButtonPushed(0); remoteControl.UndoButtonWasPushed(); Console.Write(remoteControl.ToString()); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); var light = new Light(); var stereo = new Stereo(); remoteControl.SetCommand(0, new LightOnCommand(light), new LightOffCommand(light)); remoteControl.SetCommand(1, new StereoOnCommand(stereo), new StereoOffCommand(stereo)); remoteControl.OnPush(0); remoteControl.OffPush(0); remoteControl.OnPush(1); remoteControl.OffPush(1); remoteControl.UndoPush(); Console.ReadKey(); }
static void Main(string[] args) { var light = new Light(); var garageDoor = new GarageDoor(); var ligthCmd = new LigthOnCommand(light); var garageDoorCmd = new GarageDoorOpenCommand(garageDoor); var invoker = new RemoteControl(); invoker.SetCommand(ligthCmd); invoker.OnButtonPressed(); invoker.SetCommand(garageDoorCmd); invoker.OnButtonPressed(); Console.Read(); }
static void Main(string[] args) { RemoteControl control = new RemoteControl(); Light livingRoom = new Light(); Light kitchen = new Light(); CeilingFan fan = new CeilingFan(); control.setCommand(0, new LightOnCommand(livingRoom), new LightOffCommand(livingRoom)); control.setCommand(1, new LightOnCommand(kitchen), new LightOffCommand(kitchen)); control.setCommand(2, new CeilingFanHighCommand(fan), new CeilingFanOffCommand(fan)); control.onButtonPushed(0); control.offButtonPushed(0); control.onButtonPushed(1); control.offButtonPushed(1); control.onButtonPushed(2); control.offButtonPushed(2); }
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(); }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Ligth ligth = new Ligth(); LigthOnCommand ligthGarageDoor = new LigthOnCommand(ligth); LigthOffCommand ligthOffCommand = new LigthOffCommand(ligth); GarageDoor garageDoor = new GarageDoor(ligth); GarageDoorCommandOpen garageDoorCommandOpen = new GarageDoorCommandOpen(garageDoor); GarageDoorCommandClose garageDoorCommandClose = new GarageDoorCommandClose(garageDoor); remoteControl.SetCommand(1, garageDoorCommandOpen, garageDoorCommandClose); remoteControl.SetCommand(2, ligthGarageDoor, ligthOffCommand); remoteControl.onButtonWasPushed(1); remoteControl.onButtonWasPushed(2); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { var bulb = new Bulb(); var turnOn = new TurnOn(bulb); var turnOff = new TurnOff(bulb); var remote = new RemoteControl(); remote.Submit(turnOn); remote.Submit(turnOff); turnOff.Undo(); turnOn.Redo(); Console.ReadKey(); }
private static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.Title = "Command"; var remoteControl = new RemoteControl(); var tv = new TV(); remoteControl.SetCommand(new TVOnCommand(tv)); remoteControl.PressButton(); remoteControl.PressUndo(); var microwave = new Microwave.Microwave(); // 5000 - время нагрева пищи remoteControl.SetCommand(new MicrowaveCommand(microwave, 5000)); remoteControl.PressButton(); Console.ReadKey(); }
static void Main(string[] args) { var r = new RemoteControl(); var light = new Light(); r.SetCommand(0, new LightOnCommand(light), new LightOffCommand(light)); var stereo = new Stereo(); r.SetCommand(1, new StereoOnCommand(stereo), new StereoOffCommand(stereo)); r.SetCommand(2, new StereoVolumeUpCommand(stereo), new StereoVolumeDownCommand(stereo)); r.Display(); r.OnButtonWasPushed(0); r.OffButtonWasPushed(0); r.OnButtonWasPushed(1); r.OffButtonWasPushed(2); r.OnButtonWasPushed(2); r.OffButtonWasPushed(1); r.OnButtonWasPushed(2); r.OffButtonWasPushed(2); Console.Read(); }
static void Main(string[] args) { var tv = new CommandTV("Телевизор в гостиной"); var tv2 = new CommandTV("Телевизор в спальне"); var tv3 = new CommandTV("Телевизор на кухне"); var light1 = new CommandLight("Свет в гостиной"); var remoteControl = new RemoteControl(); remoteControl.AddDevice(1, tv, "Включить/выключить телевизор в гостинной"); remoteControl.AddDevice(2, tv2, "Включить/выключить телевизор в спальне"); remoteControl.AddDevice(3, tv3, "Включить/выключить телевизор на кухне"); remoteControl.AddDevice(4, light1, "Переключить режима света в гостинной вперед"); remoteControl.AddDevice(5, light1, "Переключить режима света в гостинной назад"); remoteControl.PrintMenu(); var input = Console.ReadLine(); while (input != "0") { if (input != null) { var button = Int32.Parse(input); if (button == 5) { remoteControl.BackCommand(button); } else { remoteControl.ForwardCommand(button); } } input = Console.ReadLine(); } }
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); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); CeilingFan ceilingFan = new CeilingFan("Living Room"); //Light livingRoomLight = new Light("Living Room"); //Light kitchenLight = new Light("Kitchen"); //GarageDoor garageDoor = new GarageDoor(); //Stereo stereo = new Stereo("Living room"); //AirCondition airCondition = new AirCondition(); // //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 garageDoorUp = new GarageDoorOpenCommand(garageDoor); //GarageDoorCloseCommand garageDoorOff = new GarageDoorCloseCommand(garageDoor); // //StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); //StereoOffCommand stereoOff = new StereoOffCommand(stereo); // //AirConditionOnCommand airCondtionOnCommand = new AirConditionOnCommand(airCondition); //AirconditionOffCommand airCondtionOffCommand = new AirconditionOffCommand(airCondition); // //remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remote.SetCommand(1, kitchenLightOn, kitchenLightOff); //remote.SetCommand(2, ceilingFanOn, ceilingFanOff); //remote.SetCommand(3, stereoOnWithCD, stereoOff); //remote.SetCommand(4, airCondtionOnCommand, airCondtionOffCommand); // //Console.WriteLine(remote); // //remote.OffButtonWasPressed(0); //remote.OffButtonWasPressed(1); //remote.OffButtonWasPressed(2); //remote.OffButtonWasPressed(3); //remote.OffButtonWasPressed(4); //Console.WriteLine(); //remote.OnButtonWasPressed(0); //remote.OnButtonWasPressed(1); //remote.OnButtonWasPressed(2); //remote.OnButtonWasPressed(3); //remote.OnButtonWasPressed(4); // CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); // CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); // CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); // CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); // // remote.SetCommand(0, ceilingFanLow, ceilingFanOffCommand); // remote.SetCommand(1, ceilingFanMedium, ceilingFanOffCommand); // remote.SetCommand(2, ceilingFanHigh, ceilingFanOffCommand); // // remote.OnButtonWasPressed(0); // remote.OnButtonWasPressed(1); // remote.OnButtonWasPressed(2); // // Console.WriteLine(remote); // // remote.OffButtonWasPressed(1); // remote.UndoButtonWasPressed(); Light light = new Light("Living room"); TV tv = new TV(); Stereo stereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); LightOnCommand lightOnCommand = new LightOnCommand(light); TvOnCommand tvOnCommand = new TvOnCommand(tv); StereoOnWithCDCommand stereoOnCommand = new StereoOnWithCDCommand(stereo); HottubOnCommand hottunOnCommand = new HottubOnCommand(hottub); LightOffCommand lightOffCommand = new LightOffCommand(light); TvOffCommand tvOffCommand = new TvOffCommand(tv); StereoOffCommand stereoffCommand = new StereoOffCommand(stereo); HottubOffCommand hottunOffCommand = new HottubOffCommand(hottub); ICommand[] partyOn = { lightOnCommand, tvOnCommand, stereoOnCommand, hottunOnCommand }; ICommand[] partOff = { lightOffCommand, tvOffCommand, stereoffCommand, hottunOffCommand }; MacroCommand OnMacro = new MacroCommand(partyOn); MacroCommand OffMacro = new MacroCommand(partOff); remote.SetCommand(0, OnMacro, OffMacro); Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.UndoButtonWasPressed(); remote.OnButtonWasPressed(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(); }
static void Main(string[] args) { Light light = new Light(); GarageDoor garageDoor = new GarageDoor(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); //01.简单控制器-------------------------- Console.WriteLine("\n-----01.简单控制器-----\n"); SimpleRemoteControl remote = new SimpleRemoteControl(); remote.SetCommand(lightOn); remote.ButtonWasPressed(); remote.SetCommand(garageDoorOpen); remote.ButtonWasPressed(); //02.复杂控制器-------------------------------------- Console.WriteLine("\n-----02.复杂控制器-----\n"); RemoteControl remoteControl = new RemoteControl(); remoteControl.SetCommand(0, lightOn, lightOff); remoteControl.SetCommand(1, garageDoorOpen, garageDoorDown); Console.WriteLine(remoteControl.ToString()); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); //03.复杂控制器,撤销功能-------------------------------------- Console.WriteLine("\n-----03.复杂控制器,撤销功能-----\n"); RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo(); remoteControlWithUndo.SetCommand(0, lightOn, lightOff); remoteControlWithUndo.OnButtonWasPushed(0); remoteControlWithUndo.OffButtonWasPushed(0); Console.WriteLine(remoteControlWithUndo.ToString()); remoteControlWithUndo.UndoButtonWasPushed(); remoteControlWithUndo.OffButtonWasPushed(0); remoteControlWithUndo.OnButtonWasPushed(0); Console.WriteLine(remoteControlWithUndo.ToString()); remoteControlWithUndo.UndoButtonWasPushed(); //04.复杂撤销功能-天花板吊扇 Console.WriteLine("\n-----04.复杂撤销功能-天花板吊扇-----\n"); remoteControlWithUndo = new RemoteControlWithUndo(); CeilingFan ceilingFan = new CeilingFan("Living Room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); remoteControlWithUndo.SetCommand(0, ceilingFanHighCommand, ceilingFanOffCommand); //0号插槽的On键设置为高速,Off键设置为关闭 remoteControlWithUndo.SetCommand(1, ceilingFanMediumCommand, ceilingFanOffCommand); //1号插槽的On键设置为中速,Off键设置为关闭 remoteControlWithUndo.OnButtonWasPushed(0); //首先以高速开启吊扇 remoteControlWithUndo.OffButtonWasPushed(0); //然后关闭 Console.WriteLine(remoteControlWithUndo.ToString()); remoteControlWithUndo.UndoButtonWasPushed(); //撤销,回到中速 remoteControlWithUndo.OnButtonWasPushed(1); //开启中速 remoteControlWithUndo.OffButtonWasPushed(1); //关闭 Console.WriteLine(remoteControlWithUndo.ToString()); //撤销,回到中速 remoteControlWithUndo.UndoButtonWasPushed(); //05.Party模式 Console.WriteLine("\n-----05.Party模式-----\n"); ICommand[] partyOn = { lightOn, garageDoorOpen, ceilingFanHighCommand }; //一个数组用来记录开启命令 ICommand[] partyOff = { lightOff, garageDoorDown, ceilingFanOffCommand }; //另一个数组用来记录关闭命令 MacroCommand partyOnMacroCommand = new MacroCommand(partyOn); //创建对应的宏持有开启命令数组 MacroCommand partyOffMacroCommand = new MacroCommand(partyOff); //创建对应的宏持有关闭命令数组 remoteControlWithUndo = new RemoteControlWithUndo(); remoteControlWithUndo.SetCommand(0, partyOnMacroCommand, partyOffMacroCommand);//将宏命令指定一个按钮 Console.WriteLine(remoteControlWithUndo); Console.WriteLine("----Pushing Macro On----"); remoteControlWithUndo.OnButtonWasPushed(0); Console.WriteLine("----Pushing Macro Off----"); remoteControlWithUndo.OffButtonWasPushed(0); Console.WriteLine("----Pushing Macro Undo----"); remoteControlWithUndo.UndoButtonWasPushed(); Console.ReadKey(); }
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(); }