static void Main(string[] args) { RemoteControl remote = new RemoteControl(); 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); LightOnCommand livingRoomLightOff = new LightOnCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanHighCommand ceilingFanOn = new CeilingFanHighCommand(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); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, kitchenLightOn, kitchenLightOff); remote.SetCommand(2, ceilingFanOn, ceilingFanOff); remote.SetCommand(3, stereoOnWithCd, stereoOff); Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); remote.OffButtonWasPressed(2); remote.OnButtonWasPressed(3); remote.OffButtonWasPressed(3); }
public void Run() { RemoteControl rc = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); CeilingFan livingRoomFan = new CeilingFan("Living Room"); Tv livingRoomTv = new Tv("Living Room"); Stereo livingRoomStereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); MacroCommand onCommands = new MacroCommand(new ICommand[] { new LightOnCommand(livingRoomLight), new CeilingFanMediumCommand(livingRoomFan), new TvOnCommand(livingRoomTv), new StereoOnWithCDCommand(livingRoomStereo), new HottubOnCommand(hottub) }); MacroCommand offCommands = new MacroCommand(new ICommand[] { new LightOffCommand(livingRoomLight), new CeilingFanOffCommand(livingRoomFan), new TvOffCommand(livingRoomTv), new StereoOffCommand(livingRoomStereo), new HottubOffCommand(hottub) }); RelayCommand lightOnCommand = new RelayCommand(() => livingRoomLight.On(), () => livingRoomLight.Off()); RelayCommand lightOffCommand = new RelayCommand(() => livingRoomLight.Off(), () => livingRoomLight.On()); rc.SetCommand(0, onCommands, offCommands); rc.OnButtonPushed(0); Console.WriteLine(); rc.OffButtonPushed(0); Console.WriteLine(rc); rc.UndoButtonPushed(); Console.WriteLine(); Console.WriteLine(); rc.SetCommand(1, lightOnCommand, lightOffCommand); Console.WriteLine(rc); rc.OnButtonPushed(1); rc.OffButtonPushed(1); Console.WriteLine(); rc.UndoButtonPushed(); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); 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); LightOnCommand lightOff = new LightOnCommand(light); TvOnWithDvdCommand tvOn = new TvOnWithDvdCommand(tv); TvOffCommand tvOff = new TvOffCommand(tv); StereoOnWithCdCommand stereoOn = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); HottubOnWithBubblesCommand hottubOn = new HottubOnWithBubblesCommand(hottub); 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); remote.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remote); Console.WriteLine("-----Pressing Macro On Button-----"); remote.OnButtonWasPressed(0); Console.WriteLine("-----Pressing Macro Off Button-----"); remote.OffButtonWasPressed(0); }