static void Main(string[] args) { var remoteControl = new RemoteControl(); var ceilingFan = new CeilingFan("Living room"); var ceilingFanLowCommand = new CeilingFanLowCommand(ceilingFan); var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.PressOnButton(0); remoteControl.PressOffButton(0); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); remoteControl.PressOnButton(1); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); }
public static void Test() { var ceilingFan = new CeilingFan("living room"); var highCommand = new CeilingFanHighCommand(ceilingFan); var mediumCommand = new CeilingFanMediumCommand(ceilingFan); var lowCommand = new CeilingFanLowCommand(ceilingFan); var offCommand = new CeilingFanOffCommand(ceilingFan); var control = new AdvancedRemoteControl(); control.SetCommand(0, mediumCommand, offCommand); control.SetCommand(1, highCommand, offCommand); control.OnButtonPressed(0); control.OffButtonPressed(0); control.Undo(); control.OnButtonPressed(1); control.OffButtonPressed(1); control.Undo(); }
static void Main(string[] args) { // Setup 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(); // Command initialization var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanLow = new CeilingFanLowCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorOpenCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoWithCd = new StereoWithCdCommand(stereo); var stereoOff = new StereoOffCommand(stereo); // Remote setup remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(3, ceilingFanHigh, ceilingFanOff); remoteControl.SetCommand(4, stereoWithCd, stereoOff); // Remote with undo Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); Console.WriteLine(remoteControl); // Macro commands ICommand[] partyOn = { kitchenLightOn, livingRoomLightOn, stereoWithCd, ceilingFanMedium }; ICommand[] partyOff = { kitchenLightOff, livingRoomLightOff, stereoOff, ceilingFanOff }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(5, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("--- Pushing Macro On---"); remoteControl.OnButtonWasPushed(5); Console.WriteLine("--- Pushing Macro Off---"); remoteControl.OffButtonWasPushed(5); Console.WriteLine("--- Pushing Macro Undo---"); remoteControl.UndoButtonWasPushed(); // Ceiling fan multiple undo remoteControl.OnButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); remoteControl.UndoButtonWasPushed(); // Setting remote using lambdas instead of small classes }
static void Main(string[] args) { //SimpleRemoteControl remote = new SimpleRemoteControl(); //Light light = new Light(); //GarageDoor garageDoor = new GarageDoor(); //LightOnCommand lightOn = new LightOnCommand(light); //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); //remote.setCommand(lightOn); //remote.buttonWasPressed(); //remote.setCommand(garageOpen); //remote.buttonWasPressed(); RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo("Living Room"); CeilingFan ceilingFan = new CeilingFan("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.setCommand(2, garageOpen, garageClose); remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD); remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff); remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff); remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff); 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(5); remoteControl.offButtonWasPushed(5); Console.WriteLine(remoteControl); remoteControl.undoButtonWasPushed(); remoteControl.onButtonWasPushed(4); Console.WriteLine(remoteControl); remoteControl.undoButtonWasPushed(); #region marco command Command[] partyOn = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD }; Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD }; MacroCommand partyOnCommand = new MacroCommand(partyOn); MacroCommand partyOffCommand = new MacroCommand(partyOff); remoteControl.setCommand(6, partyOnCommand, partyOffCommand); remoteControl.onButtonWasPushed(6); remoteControl.offButtonWasPushed(6); remoteControl.undoButtonWasPushed(); #endregion Console.ReadLine(); }