public static void RunRemoteControlWithMacroCommand() { 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 stereoOff = new StereoOffCommand(stereo); var macroOnCommand = new MacroCommand(new ICommand[] { lightOn, garageDoorOpen, stereoOnWithCD }); var macroOffCommand = new MacroCommand(new ICommand[] { lightOff, garageDoorClose, stereoOff }); var remote = new RemoteControl(); remote.SetCommand(0, macroOnCommand, macroOffCommand); System.Console.WriteLine(remote); System.Console.WriteLine("--- Pushing Macro on ---"); remote.OnButtonWasPressed(0); System.Console.WriteLine("--- Pushing Macro off ---"); remote.OffButtonWasPressed(0); }
public static void RunRemoteControl() { var remote = new RemoteControl(); 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 stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); remote.SetCommand(2, stereoOnWithCD, stereoOff); System.Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); remote.OffButtonWasPressed(2); }
static void Main(string[] args) { // Control the light var remote = new RemoteController(); // Invoker var light = new Light(); // Receiver var lightOn = new LightOnCommand(light); // Command var lightOff = new LightOffCommand(light); // Command remote.SetCommand(lightOn); remote.ActivateCommand(); remote.SetCommand(lightOff); remote.ActivateCommand(); // Control the garage door var garageDoor = new GarageDoor(); // Receiver var doorUp = new GarageDoorUpCommand(garageDoor); // Command var doorDown = new GarageDoorDownCommand(garageDoor); // Command // Invoker ---> Command ----> Receiver remote.SetCommand(doorUp); remote.ActivateCommand(); remote.SetCommand(doorDown); remote.ActivateCommand(); Console.ReadKey(); }
public static void Start() { var remoteControl = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnCommand(stereo); var stereoOff = new StereoOffCommand(stereo); var ceililngFan = new CeilingFan("Kitchen room"); var ceililngFanLowOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low); var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium); var ceililngFanHighOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High); var ceililngFanOff = new CeilingFanOffCommand(ceililngFan); var partyOn = new MacroCommand(new ICommand[] { lightOn, stereoOn }); var partyOff = new MacroCommand(new ICommand[] { lightOff, stereoOff }); remoteControl.SetCommand(2, lightOn, lightOff); remoteControl.SetCommand(3, stereoOn, stereoOff); remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff); remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff); remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff); remoteControl.SetCommand(1, partyOn, partyOff); remoteControl.P(); RemoteControlPressButtons(remoteControl); }
public static void UnCommandTest() { // 实例化遥控器 RemoteControl remoteControl = new RemoteControl(); // 实例化需要控制对象,并传入房子位置 Light light = new Light("客厅"); // 调用设备开关方法 LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); // 设置插槽位置(遥控器的哪个按钮对应哪个设备开关) remoteControl.SetCommand(0, lightOn, lightOff); // 按下开关 remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); // 输出插槽位置 Console.WriteLine(remoteControl); // 撤销 Console.WriteLine("按下撤销按钮"); remoteControl.UndoButtonWasPushed(); Console.WriteLine(""); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(0); Console.WriteLine(remoteControl); Console.WriteLine("按下撤销按钮"); remoteControl.UndoButtonWasPushed(); }
public static void MacroCommandTests() { var light = new Light("Living Room"); var tv = new TV("Living Room"); var stereo = new Stereo("Living Room"); var hottub = new Hottub(); var lightOn = new LightOnCommand(light); var stereoOn = new StereoOnWithCdCommand(stereo); var tvOn = new TvOnCommand(tv); var hottubOn = new HottubOnCommand(hottub); var lightOff = new LightOffCommand(light); var stereoOff = new StereoOffCommand(stereo); var tvOff = new TvOffCommand(tv); var hottubOff = new HottubOffCommand(hottub); IUndoableCommand[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; IUndoableCommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); var remoteControl = new RemoteControl(); remoteControl.SetCommand(1, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("---Pushing Macro On-- -"); remoteControl.OnButtonWasPushed(1); Console.WriteLine("---Pushing Macro Off-- -"); remoteControl.OffButtonWasPushed(1); Console.ReadKey(); }
private void button9_Click(object sender, EventArgs e) { richTextBox1.Text = null; foreach (var buf in label) { if (buf.BackColor != Color.MediumTurquoise) { buf.BackColor = Color.MediumTurquoise; } } label9.BackColor = Color.MediumSeaGreen; if (label9.BackColor == Color.MediumSeaGreen & flag == true) { RemoteControl remoteControl = new RemoteControl(); Light light = new Light(richTextBox1); LightOnCommand lightOnCommand = new LightOnCommand(light); LightOffCommand lightOffCommand = new LightOffCommand(light); remoteControl.SetCommand(1, lightOnCommand, lightOffCommand); remoteControl.OffButtonWasPushed(1); flag = false; } else { richTextBox1.Text = null; richTextBox1.Text = "Light is Off\nPress key On light"; } }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light livingroomLight = new Light(); LightOnCommand livingroomLightOnCommand = new LightOnCommand(livingroomLight); LightOffCommand livingroomLightOffCommand = new LightOffCommand(livingroomLight); Light bedroomLight = new Light(); LightOnCommand bedroomLightOnCommand = new LightOnCommand(bedroomLight); LightOffCommand bedroomLightOffCommand = new LightOffCommand(bedroomLight); remote.SetCommand(0, livingroomLightOnCommand, livingroomLightOffCommand); remote.SetCommand(1, bedroomLightOnCommand, bedroomLightOffCommand); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); Console.WriteLine($"Bedroom light: {livingroomLight.State}"); remote.OnButtonPressed(0); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); remote.OffButtonPressed(0); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); remote.OnButtonPressed(1); Console.WriteLine($"Bedroom light: {bedroomLight.State}"); remote.OffButtonPressed(1); Console.WriteLine($"Bedroom light: {bedroomLight.State}"); Console.ReadKey(); }
static void Main(string[] args) { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light(false, "Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room", CeilingFan.Off); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan); CeilingFanLowCommand ceilingFanLowCommand = new CeilingFanLowCommand(livingRoomCeilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.SetCommand(2, ceilingFanLowCommand, ceilingFanOffCommand); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); }
private static void CommandPattern() { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light light = new Light("Living Room"); TV tv = new TV("Living Room"); Stereo stereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); StereoOffCommand stereoOff = new StereoOffCommand(stereo); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.setCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("--- Pushing Macro On ---"); remoteControl.onButtonWasPushed(0); Console.WriteLine("--- Pushing Macro Off ---"); remoteControl.offButtonWasPushed(0); }
private static string ProcessRemoteControlWithUndo() { StringBuilder sb = new StringBuilder(); RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo(); Light livingRoomLight = new Light("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControlWithUndo.OnCommands[0] = livingRoomLightOn; remoteControlWithUndo.OffCommands[0] = livingRoomLightOff; sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.ToString()); sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed()); sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.ToString()); sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed()); return(sb.ToString()); }
public void MacroCommandtest() { Remote remote = new Remote(); Light light = new Light(); Stero stero = new Stero(); Fan fan = new Fan(); LightOnCommand lightOn = new LightOnCommand(light); SteroOnWithCDCommand steroOn = new SteroOnWithCDCommand(stero); FanHighCommand fanOn = new FanHighCommand(fan); LightOffCommand lightOff = new LightOffCommand(light); SteroOffCommand steroOff = new SteroOffCommand(stero); FanOffCommand fanOff = new FanOffCommand(fan); MacroCommand macroCommandOn = new MacroCommand(new ICommand[] { lightOn, steroOn, fanOn }); MacroCommand macroCommandOff = new MacroCommand(new ICommand[] { lightOff, steroOff, fanOff }); remote.SetCommnd(0, macroCommandOn, macroCommandOff); remote.OnButtonPressed(0); Assert.AreEqual(Light.States.On, light.CurrentState); Assert.AreEqual(Stero.State.CD, stero.CurrentState); Assert.AreEqual((int)11, stero.Volume); Assert.AreEqual(Fan.Speed.High, fan.CurrentSpeed); remote.OffButtonPressed(0); Assert.AreEqual(Light.States.Off, light.CurrentState); Assert.AreEqual(Stero.State.Off, stero.CurrentState); Assert.AreEqual((int)0, stero.Volume); Assert.AreEqual(Fan.Speed.Off, fan.CurrentSpeed); }
static void Main(string[] args) { var remote = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffWithCDCommand(stereo); var ceilingFan = new CeilingFan("Living Room"); var ceilingFanHighOn = new CeilingFanHighCommand(ceilingFan); var macro = new MacroCommand(new ICommand[] {lightOn, stereoOn}); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(2, stereoOn, stereoOff); remote.SetCommand(3, ceilingFanHighOn, new NoComand()); remote.SetCommand(4, macro, new NoComand()); remote.OnButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(0); remote.OffButtonWasPushed(1); remote.OffButtonWasPushed(2); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(3); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(4); remote.UndoButtonWasPushed(); Console.ReadKey(); }
static void Main(string[] args) { RemoteControlInfo remoteControl = new RemoteControlInfo(); LightInfo livingRoomLight = new LightInfo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); Console.WriteLine("--== Living Room Light ==--"); remoteControl.OnButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); CeilingFanInfo drawingRoomCeilingFan = new CeilingFanInfo("Drawing Room"); CeilingFanHighCommand drawingRoomCeilingFanHigh = new CeilingFanHighCommand(drawingRoomCeilingFan); CeilingFanLowCommand drawingRoomCeilingFanLow = new CeilingFanLowCommand(drawingRoomCeilingFan); remoteControl.SetCommand(1, drawingRoomCeilingFanHigh, drawingRoomCeilingFanLow); Console.WriteLine("--== Drawing Room Ceiling Fan ==--"); remoteControl.OnButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(1); Console.ReadLine(); }
public void CommandExampleMacros() { RemoteControl remote = new RemoteControl(); // this is the invoker Light livingRoomLight = new Light("Living Room"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); ICommand[] partyOn = { livingRoomLightOn, stereoOnWithCd }; ICommand[] partyOff = { livingRoomLightOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remote.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remote); Console.WriteLine("--- Pushing Macro On ---\n"); remote.OnButtonWasPushed(0); Console.WriteLine("--- Pushing Macro Off ---\n"); remote.OffButtonWasPushed(0); Console.WriteLine("--- Pushing Macro Undo ---\n"); // not working for every scenario remote.UndoButtonWasPushed(); Console.ReadLine(); }
private void Button3_Click(object sender, EventArgs e) { RemoteControl remoteControl = new RemoteControl(3); Light light = new Light(); Fan fan = new Fan(); LightOnCommand lightOnCommand = new LightOnCommand(light); LightOffCommand lightOffCommand = new LightOffCommand(light); FanOnCommand fanOnCommand = new FanOnCommand(fan); FanOffCommand fanOffCommand = new FanOffCommand(fan); Command[] onCommands = { lightOnCommand, fanOnCommand }; Command[] offCommands = { lightOffCommand, fanOffCommand }; MacroCommand onMacro = new MacroCommand(onCommands); MacroCommand offMacro = new MacroCommand(offCommands); remoteControl.setCommand(0, onMacro, offMacro); salida.Text = remoteControl.toString() + " "; salida.Text += "\n" + remoteControl.onButtonWasPushed(0); salida.Text += "\n" + remoteControl.offButtonWasPushed(0); }
public static void CommandTest() { // 实例化遥控器 RemoteControl remoteControl = new RemoteControl(); // 实例化需要控制对象,并传入房子位置 Stereo stereo = new Stereo("客厅"); Light light = new Light("客厅"); TV tv = new TV("卧室"); // 调用设备开关方法 StereoOnWithCDCommand stereoOnWichCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOffWithCD = new StereoOffCommand(stereo); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); TVOnCommand tvOn = new TVOnCommand(tv); TVOffCommand tvOff = new TVOffCommand(tv); // 设置插槽位置(遥控器的哪个按钮对应哪个设备开关) remoteControl.SetCommand(0, lightOn, lightOff); remoteControl.SetCommand(3, stereoOnWichCD, stereoOffWithCD); remoteControl.SetCommand(5, tvOn, tvOff); // 输出插槽位置 Console.WriteLine(remoteControl); // 按下开关 remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.OnButtonWasPushed(5); remoteControl.OffButtonWasPushed(5); }
private static string ProcessMacroCommand() { StringBuilder sb = new StringBuilder(); RemoteControl remoteControl = new RemoteControl(); Light light = new Light("Living Room"); Stereo stereo = new Stereo(); LightOnCommand lightOn = new LightOnCommand(light); StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo); LightOffCommand lightOff = new LightOffCommand(light); StereoOffCommand stereoOff = new StereoOffCommand(stereo); ICommand[] partyOn = { lightOn, stereoOn }; ICommand[] partyOff = { lightOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.OnCommands[0] = partyOnMacro; remoteControl.OffCommands[0] = partyOffMacro; sb.AppendLine(remoteControl.ToString()); sb.AppendLine("--- Pushing Macro On ---"); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine("--- Pushing Macro Off ---"); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); return(sb.ToString()); }
public static void MacroCommandExample() { Light light = new Light("Living Room"); TV tv = new TV("Living Room"); Stereo stereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); StereoOffCommand stereoOff = new StereoOffCommand(stereo); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); ICommand[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; ICommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); RemoteControl remoteControl = new RemoteControl(); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl.ToString()); Console.WriteLine("\n--- Pushing Macro On---"); remoteControl.OnButtonPushed(0); Console.WriteLine("\n--- Pushing Macro Off---"); remoteControl.OffButtonPushed(0); }
public void Load() { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); Light light = new Light(); TV tv = new TV(); Hottub hottub = new Hottub(); 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); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCd = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; 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, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(4, stereoOnWithCd, stereoOff); remoteControl.SetCommand(5, garageDoorUp, garageDoorDown); remoteControl.SetCommand(6, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); for (int i = 0; i <= 6; i++) { remoteControl.OnButtonWasPushed(i); remoteControl.OffButtonWasPushed(i); remoteControl.UndoButtonWasPushed(); } }
private static void Main() { var remote = new RemoteControl(); 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); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); Console.WriteLine(remote); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); Console.WriteLine(remote); Console.ReadKey(); }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Light bedroomLight = new Light("卧室灯"); Light kitchenLight = new Light("厨房灯"); CeilingFan ceilingFan = new CeilingFan("吊扇"); LightOnCommand bedroomLightOnCommand = new LightOnCommand(bedroomLight); LightOffCommand bedroomLightOffCommand = new LightOffCommand(bedroomLight); LightOffCommand kitchenLightOffCommand = new LightOffCommand(kitchenLight); LightOnCommand kitchenLightOnCommand = new LightOnCommand(kitchenLight); FanOnCommand ceilingFanHighCommand = new FanOnCommand(ceilingFan, CeilingFan.HighSpeed); FanOnCommand ceilingFanMediumCommand = new FanOnCommand(ceilingFan, CeilingFan.MediumSpeed); FanOnCommand ceilingFanLowCommand = new FanOnCommand(ceilingFan, CeilingFan.LowSpeed); FanOffCommand ceilingFanOffCommand = new FanOffCommand(ceilingFan); remoteControl.SetCommond(0, bedroomLightOnCommand, bedroomLightOffCommand); remoteControl.SetCommond(1, kitchenLightOnCommand, kitchenLightOffCommand); remoteControl.SetCommond(2, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.SetCommond(3, ceilingFanMediumCommand, ceilingFanOffCommand); remoteControl.SetCommond(4, ceilingFanLowCommand, bedroomLightOnCommand); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(4); }
public static void Main(string[] args) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Chapter6 - Command"); Console.WriteLine(); SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); RemoteControl rc = new RemoteControl(); Console.WriteLine(rc.ToString()); Light lightInBedroom = new Light(); LightOnCommand lightInBedroom_OnCommand = new LightOnCommand(lightInBedroom); LightOffCommand lightInBedroom_OffCommand = new LightOffCommand(lightInBedroom); Stereo myStereo = new Stereo(); StereoOnWithCDCommand myStereo_On = new StereoOnWithCDCommand(myStereo); StereoOffWithCDCommand myStereo_Off = new StereoOffWithCDCommand(myStereo); CeilingFan fan = new CeilingFan("Living room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(fan); MacroCommand macroCommand_On = new MacroCommand(new ICommand[] { lightInBedroom_OnCommand, myStereo_On, ceilingFanHighCommand }); MacroCommand macroCommand_Off = new MacroCommand(new ICommand[] { lightInBedroom_OffCommand, myStereo_Off, ceilingFanOffCommand }); rc.SetCommand(0, lightInBedroom_OnCommand, lightInBedroom_OffCommand); rc.SetCommand(1, myStereo_On, myStereo_Off); rc.SetCommand(2, ceilingFanHighCommand, ceilingFanOffCommand); rc.SetCommand(6, macroCommand_On, macroCommand_Off); Console.WriteLine(rc.ToString()); rc.OnButtonWasPressed(0); rc.OnButtonWasPressed(1); rc.OffButtonWasPressed(0); rc.UndoButtonWasPressed(); rc.OnButtonWasPressed(2); rc.UndoButtonWasPressed(); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Call macro command"); rc.OnButtonWasPressed(6); rc.OffButtonWasPressed(6); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Macro command finished"); Console.WriteLine(); Console.WriteLine(rc.ToString()); Console.ReadKey(); }
static void Main(string[] args) { var control = new RemoteControl(); var tv = new TV(); var kitchenLight = new Light("Kitchen"); var yardLight = new Light("Yard"); var livingRoomLight = new Light("Living Room"); var bathroomLight = new Light("Bathroom"); var bedroomLight = new Light("Bedroom"); var lightOnKitchen = new LightOnCommand(kitchenLight); var lightOnYard = new LightOnCommand(yardLight); var lightOnLivingR = new LightOnCommand(livingRoomLight); var lightOnBathR = new LightOnCommand(bathroomLight); var lightOnBedR = new LightOnCommand(bedroomLight); var lightOffKitchen = new LightOffCommand(kitchenLight); var lightOffYard = new LightOffCommand(yardLight); var lightOffLivingR = new LightOffCommand(livingRoomLight); var lightOffBathR = new LightOffCommand(bathroomLight); var lightOffBedR = new LightOffCommand(bedroomLight); control.SetCommand(Slot.Num0, new TVOnCommand(tv), new TVOffCommand(tv)); control.SetCommand(Slot.Num1, lightOnKitchen, lightOffKitchen); control.SetCommand(Slot.Num2, lightOnYard, lightOffYard); control.SetCommand(Slot.Num3, new MacroCommand(lightOnKitchen, lightOnYard, lightOnLivingR, lightOnBathR, lightOnBedR), new MacroCommand(lightOffKitchen, lightOffYard, lightOffLivingR, lightOffBathR, lightOffBedR)); Console.WriteLine(control.ToString() + '\n'); control.OnButtonPressed(Slot.Num0); control.OffButtonPressed(Slot.Num0); control.OnButtonPressed(Slot.Num1); control.OffButtonPressed(Slot.Num1); control.OnButtonPressed(Slot.Num2); control.OffButtonPressed(Slot.Num2); Console.WriteLine('\n'); control.UndoButtonPressed(); control.UndoButtonPressed(); control.UndoButtonPressed(); Console.WriteLine('\n'); control.OnButtonPressed(Slot.Num4); Console.WriteLine('\n'); control.OnButtonPressed(Slot.Num3); control.UndoButtonPressed(); Console.ReadKey(); }
private void Form1_Load(object sender, EventArgs e) { panel1.BackColor = Color.DarkGray; lightOnCommand = new LightOnCommand(light); lightOffCommand = new LightOffCommand(light); remote.SetCommand(lightOnCommand); remote2.SetCommand(lightOffCommand); light.onActiveChanged += Lightning; }
public static void Run() { var remoteControl = new RemoteControlWithUndo(); var livingRoomLight = new Light("Living Room"); var ceilingFan = new CeilingFan("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(2); Console.WriteLine(); }
private static string ProcessRemoteControl() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garage = new GarageDoor(); Stereo stereo = new Stereo(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garage); GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remoteControl.OnCommands[0] = livingRoomLightOn; remoteControl.OnCommands[1] = kitchenLightOn; remoteControl.OnCommands[2] = ceilingFanOnCommand; remoteControl.OnCommands[3] = stereoOnWithCDCommand; remoteControl.OffCommands[0] = livingRoomLightOff; remoteControl.OffCommands[1] = kitchenLightOff; remoteControl.OffCommands[2] = ceilingFanOffCommand; remoteControl.OffCommands[3] = stereoOffCommand; StringBuilder sb = new StringBuilder(); sb.AppendLine(remoteControl.ToString()); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); sb.AppendLine(remoteControl.OnButtonWasPushed(1)); sb.AppendLine(remoteControl.OffButtonWasPushed(1)); sb.AppendLine(remoteControl.OnButtonWasPushed(2)); sb.AppendLine(remoteControl.OffButtonWasPushed(2)); sb.AppendLine(remoteControl.OnButtonWasPushed(3)); sb.AppendLine(remoteControl.OffButtonWasPushed(3)); return(sb.ToString()); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); var light = new Light("Living Roon"); var tv = new TV("Living Room"); var stereo = new Stereo("Living Room"); var hottub = new Hottub(); var garageDoor = new GarageDoor(string.Empty); var lightOnCommand = new LightOnCommand(light); var lightOffCommand = new LightOffCommand(light); var stereoOnCommand = new StereoOnCommand(stereo); var stereoOffCommand = new StereoOffCommand(stereo); var tvOnCommand = new TVOnCommand(tv); var tvOffCommand = new TVOffCommand(tv); var hottubOnCommand = new HottubOnCommand(hottub); var hottubOffCommand = new HottubOffCommand(hottub); var partyOn = new ICommand[] { lightOnCommand, stereoOnCommand, tvOnCommand, hottubOnCommand }; var partyOff = new ICommand[] { lightOffCommand, stereoOffCommand, tvOffCommand, hottubOffCommand }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); //remoteControl.SetCommand(0, lightOnCommand, lightOffCommand); //remoteControl.SetCommand(1, tvOnCommand, tvOffCommand); //remoteControl.SetCommand(2, stereoOnCommand, stereoOffCommand); //remoteControl.SetCommand(3, hottubOnCommand, hottubOffCommand); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); remoteControl.SetCommand(6, new GarageDoorUpCommand(garageDoor), new GarageDoorDownCommand(garageDoor)); Console.WriteLine(remoteControl); remoteControl.OnButtonPressed(2); remoteControl.OnButtonPressed(0); remoteControl.OnButtonPressed(3); remoteControl.OnButtonPressed(1); remoteControl.OffButtonPressed(2); remoteControl.OffButtonPressed(0); remoteControl.OffButtonPressed(3); remoteControl.OffButtonPressed(1); remoteControl.OnButtonPressed(6); remoteControl.UndoButtonPressed(); Console.Read(); }
public static void Run() { var remoteControl = new RemoteControl(); 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 livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorUpCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); remoteControl.OnButtonWasPushed(3); Console.WriteLine(); remoteControl.OffButtonWasPushed(3); }
static void Main(string[] args) { SimpleRemoteControl simpleRemoteControl = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOnCommand = new LightOnCommand(light); simpleRemoteControl.Command = lightOnCommand; simpleRemoteControl.PressButton(); LightOffCommand lightOffCommand = new LightOffCommand(light); simpleRemoteControl.Command = lightOffCommand; simpleRemoteControl.PressButton(); }
static void Main(string[] args) { Remote remote = new Remote(); Light livingroomlight = new Light("livingroom"); LightOnCommand livingroomlighton = new LightOnCommand(livingroomlight); LightOffCommand livingroomlightoff = new LightOffCommand(livingroomlight); remote.SetCommand(0, livingroomlighton, livingroomlightoff); remote.OnButtonWasPushed(0); //livingroom light is on SimpleRemoteControl remote2 = new SimpleRemoteControl(); remote2.SetCommand(livingroomlighton); remote2.ButtonWasPressed(); //livingroom light is on string z = Console.ReadLine(); }
static void Main(string[] args) { #region SimpleRemoteControl //var remote = new SimpleRemoteControl(); //var lightOn = new LightOnCommand(new Light()); //remote.Slot = lightOn; //remote.ButtonWasPressed(); //Console.WriteLine("-----------------------------------------------------------"); //var doorOpen = new DoorOpenCommand(new Door()); //remote.Slot = doorOpen; //remote.ButtonWasPressed(); #endregion #region RemoteControl var remote = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var door = new Door(); var doorOpen = new DoorOpenCommand(door); var doorClose = new DoorCloseCommand(door); var stereo = new Stereo(); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, doorOpen, doorClose); remote.SetCommand(2, stereoOnWithCD, stereoOff); Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); remote.OffButtonWasPressed(2); remote.UndoButtonWasPressed(); #endregion Console.ReadKey(); }
static void Main(string[] args) { LightOffCommand livingRoomLightOff, kitchenLightOff; LightOnCommand livingRoomLightOn, kitchenLightOn; Light livingRoomLight = new Light("\nЖилая комната\n"); Console.WriteLine(livingRoomLight.On()); Light kitchenLight = new Light("\nКухня\n"); Console.WriteLine(kitchenLight.On()); ///Создание команд для управления освещением livingRoomLightOn = new LightOnCommand(livingRoomLight); livingRoomLightOn.Execute(); kitchenLightOn = new LightOnCommand(kitchenLight); kitchenLightOn.Execute(); Console.WriteLine(livingRoomLight.Off()); Console.WriteLine(kitchenLight.Off()); ///Создание команд для управления освещением livingRoomLightOff = new LightOffCommand(livingRoomLight); livingRoomLightOn.Execute(); kitchenLightOff= new LightOffCommand(kitchenLight); kitchenLightOff.Execute(); ///Создание команд для управления сауной Hottub hottub = new Hottub(); Console.WriteLine(hottub.Heat()); HottubOnCommand HottubOn = new HottubOnCommand(hottub); HottubOn.Execute(); Console.WriteLine(hottub.Cool()); HottubOffCommand HottubOff = new HottubOffCommand(hottub); Console.WriteLine(HottubOff.Execute()); CeilingFan ceilingFan = new CeilingFan("\nЖилая комната\n"); Console.WriteLine(ceilingFan.High()); ///Создание команд управления потолочным вентилятором CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); ceilingFanOn.Execute(); GarageDoor garageDoor = new GarageDoor("\n Дверь гаража\n "); Console.WriteLine(garageDoor.Up()); ///Создание команд для управления дверью гаража GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); garageDoorUp.Execute(); Console.WriteLine(garageDoor.LightOn()); garageDoorUp.Execute(); Console.WriteLine(garageDoor.Stop()); garageDoorUp.Execute(); Stereo stereo = new Stereo("\nЖилая комната\n"); Console.WriteLine(stereo.On()); Console.WriteLine(stereo.SetCD()); Console.WriteLine(stereo.SetDVD()); ///создание команд для управления стереосистемами StereoOnWithCDCommand stereoOnwithCD = new StereoOnWithCDCommand(stereo); stereoOnwithCD.Execute(); Console.WriteLine(stereo.Off()); ///создание команд для управления стереосистемами StereoOffCommand stereoOffwithCD = new StereoOffCommand(stereo); Console.WriteLine(stereoOffwithCD.Execute()); Stereo stereo2 = new Stereo("\n\nКухня \n"); Console.WriteLine(stereo2.Off()); ///создание команд для управления стереосистемами StereoOffCommand stereoOffwithCD2 = new StereoOffCommand(stereo2); Console.WriteLine(stereoOffwithCD2.Execute()); Console.ReadKey(); }