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(); }
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(); }
static void Main(string[] args) { CeilingFan cf = new CeilingFan(); CeilingFanHighCommand cfh = new CeilingFanHighCommand(cf); CeilingFanLowCommand cfl = new CeilingFanLowCommand(cf); Control ctr = new Control(); // 假设 button0, button1 分别为高速低速 ctr.SetCommand(0, cfh); ctr.SetCommand(1, cfl); ctr.OnButtonWasPressed(0); ctr.OnButtonWasPressed(1); ctr.UndoButtonWasPressed(); ctr.RedoButtonWasPressed(); }