static void Main(string[] args) { #region Simple remote control test //Light light = new Light(); //Command lightOn = new LightOnCommand(light); //SimpleRemoteControl remote = new SimpleRemoteControl(); //remote.SetCommand(lightOn); //remote.ButtonPressed(); //GarageDoor door = new GarageDoor(); //GaraDoorOpenCommand garageOpen = new GaraDoorOpenCommand(door); //remote.SetCommand(garageOpen); //remote.ButtonPressed(); #endregion #region remote control //Light kitchenLight = new Light("kichen"); //Light bedroomLight = new Light("bedroom"); //Stereo parlorStereo = new Stereo("parlor"); //Stereo washRommStereo = new Stereo("washroom"); //GarageDoor garageDoor = new GarageDoor(string.Empty); //LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); //LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); //StereoOnWithCDCommand parlorStereoOn = new StereoOnWithCDCommand(parlorStereo); //StereoOffCommand parloStereoOff = new StereoOffCommand(parlorStereo); //GaraDoorOpenCommand garageDoorOpen = new GaraDoorOpenCommand(garageDoor); //GaraDoorCloseCommand garageDoorClose = new GaraDoorCloseCommand(garageDoor); //RemoteControl remoteControl = new RemoteControl(); //remoteControl.SetCommand(0, kitchenLightOn, kitchenLightOff); //remoteControl.SetCommand(1, parlorStereoOn, parloStereoOff); //remoteControl.SetCommand(2, garageDoorOpen, garageDoorClose); //remoteControl.OnButtonWasPushed(2); //remoteControl.OffButtonWasPushed(2); //remoteControl.OnButtonWasPushed(1); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.OffButtonWasPushed(1); //remoteControl.OnButtonWasPushed(3); //remoteControl.OffButtonWasPushed(4); #endregion #region remote control with undo //Light livintRoomLight = new Light("livingroom"); //LightOnCommand livingRoomOn = new LightOnCommand(livintRoomLight); //LightOffCommand livingRommOff = new LightOffCommand(livintRoomLight); //RemoteControlWithUndo remoteUndo = new RemoteControlWithUndo(); //remoteUndo.SetCommand(0, livingRoomOn, livingRommOff); //remoteUndo.OnButtonWasPushed(0); //remoteUndo.OffButtonWasPushed(0); //Console.WriteLine(remoteUndo.ToString()); //remoteUndo.UndoButtonWasPushed(); //remoteUndo.OffButtonWasPushed(0); //remoteUndo.OnButtonWasPushed(0); //Console.WriteLine(remoteUndo.ToString()); //remoteUndo.UndoButtonWasPushed(); #endregion #region remote control with multiple undo states //RemoteControlWithUndo remote = new RemoteControlWithUndo(); //CeilingFan fan = new CeilingFan("livingroom"); //CeilingFanHighSpeedCommand ceilingFanHigh = new CeilingFanHighSpeedCommand(fan); //CeilingFanLowSpeedCommand ceilingFanLow = new CeilingFanLowSpeedCommand(fan); //CeilingFanOffSpeedCommand ceilingFanOff = new CeilingFanOffSpeedCommand(fan); //remote.SetCommand(0, ceilingFanHigh, ceilingFanOff); //remote.SetCommand(1, ceilingFanLow, ceilingFanOff); //remote.OnButtonWasPushed(0); //remote.OffButtonWasPushed(0); //Console.WriteLine(remote.ToString()); //remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(1); //Console.WriteLine(remote.ToString()); //remote.UndoButtonWasPushed(); #endregion #region remote control with macro commands RemoteControlWithUndo remote = new RemoteControlWithUndo(); Light light = new Light("livingroom"); Stereo stero = new Stereo("livingroom"); CeilingFan fan = new CeilingFan("livingroom"); LightOnCommand livingLightOn = new LightOnCommand(light); StereoOnWithCDCommand livingStereoOn = new StereoOnWithCDCommand(stero); CeilingFanMediumSpeedCommand livingCeilingMedium = new CeilingFanMediumSpeedCommand(fan); LightOffCommand livingLightOff = new LightOffCommand(light); StereoOffCommand livingStereoOff = new StereoOffCommand(stero); CeilingFanOffSpeedCommand livingCeilingOff = new CeilingFanOffSpeedCommand(fan); Command[] macroOnCmd = { livingLightOn, livingStereoOn, livingCeilingMedium }; Command[] macroOffCmd = { livingLightOff, livingStereoOff, livingCeilingOff }; MacroCommand macroOn = new MacroCommand(macroOnCmd); MacroCommand macroOff = new MacroCommand(macroOffCmd); remote.SetCommand(0, macroOn, macroOff); Console.WriteLine(remote.ToString()); remote.OnButtonWasPushed(0); Console.WriteLine("------push macro on-----"); remote.OffButtonWasPushed(0); Console.WriteLine("------push macro off----"); #endregion Console.Read(); }
static void Main(string[] args) { var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Bedroom"); var lightOnCommand = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOnCommand); simpleRemoteControl.ButtonWasPressed(); var door = new GarageDoor(""); var garageDoorOpenCommand = new GarageDoorOpenCommand(door); simpleRemoteControl.SetCommand(garageDoorOpenCommand); simpleRemoteControl.ButtonWasPressed(); Console.WriteLine(); 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 livingRoomLightOnCommand = new LightOnCommand(livingRoomLight); var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight); var kitchenLightOnCommand = new LightOnCommand(kitchenLight); var kitchenLightOffCommand = new LightOffCommand(kitchenLight); var ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); var garageDoorUpCommand = new GarageDoorOpenCommand(garageDoor); var garageDoorDownCommand = new GarageDoorCloseCommand(garageDoor); var stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo); var stereoOffCommand = new StereoOffCommand(stereo); var remote = new RemoteControl(); remote.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); remote.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand); remote.SetCommand(2, ceilingFanOnCommand, ceilingFanOffCommand); remote.SetCommand(3, stereoOnWithCdCommand, stereoOffCommand); Console.WriteLine(remote.ToString()); Console.WriteLine(); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(2); remote.OnButtonWasPushed(3); remote.OffButtonWasPushed(3); Console.WriteLine(); Console.WriteLine("------------ Remote with Undo ------------"); var remoteWithUndo = new RemoteControlWithUndo(); var sunRoomLight = new Light("Sun Room"); var sunRoomLightOnCommand = new LightOnCommand(sunRoomLight); var sunRoomLightOffCommand = new LightOffCommand(sunRoomLight); remoteWithUndo.SetCommand(0, sunRoomLightOnCommand, sunRoomLightOffCommand); remoteWithUndo.OnButtonWasPushed(0); remoteWithUndo.OffButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); remoteWithUndo.OffButtonWasPushed(0); remoteWithUndo.OnButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); Console.WriteLine(); Console.WriteLine("------------ Ceiling Fan with Undo ------------"); remoteWithUndo = new RemoteControlWithUndo(); var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); remoteWithUndo.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand); remoteWithUndo.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteWithUndo.OnButtonWasPushed(0); remoteWithUndo.OffButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); remoteWithUndo.OnButtonWasPushed(1); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); Console.WriteLine(); Console.WriteLine("------------ Party Mode (Macro Commands) ------------"); remoteWithUndo = new RemoteControlWithUndo(); ICommand[] partyOn = { livingRoomLightOnCommand, stereoOnWithCdCommand, ceilingFanMediumCommand }; ICommand[] partyOff = { livingRoomLightOffCommand, stereoOffCommand, ceilingFanOffCommand }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); remoteWithUndo.SetCommand(0, partyOnMacro, partyOffMacro); remoteWithUndo.OnButtonWasPushed(0); Console.WriteLine(); remoteWithUndo.OffButtonWasPushed(0); Console.ReadLine(); }