public static void Main(String[] args) { // get the singleton only instance of the remote control RemoteControl remoteControl = RemoteControl.getInstance(); // create all the receiver devices in their proper locations Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo <string, string, object, int> stereo = new Stereo <string, string, object, int>("Living Room"); // create all the light command objects LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); // create the on and off commands for the ceiling fan CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); // create the up and down commands for the garage door GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); // create the stereo on and off commands StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); // load commands into the remote slots remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); // print each remote slot and the command that it is assigned to Console.WriteLine(remoteControl); // push on and off button through each slot remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); for (int i = 0; i < remoteControl.OnCommands.Length; i++) { remoteControl.UndoButtonWasPushed(); } }
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) { /*var remote = new SimpleRemoteControl(); * * var light = new Light(); * var garageDoor = new GarageDoor(); * * var lightOnCommand = new LigthOnCommand(light); * var garageOpenCommand = new GarageDoorOpenCommand(garageDoor); * * remote.SetCommand(lightOnCommand); * remote.ButtonWasPressed(); * remote.SetCommand(garageOpenCommand); * remote.ButtonWasPressed();*/ var remoteControl = new RemoteControl(); var livigRoomLight = 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(livigRoomLight); var livingRoomLightOff = new LightOffCommand(livigRoomLight); var kitchenRoomLightOn = new LightOnCommand(kitchenLight); var kitchenRoomLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorOpenCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenRoomLightOn, kitchenRoomLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); Console.WriteLine("-----------------------------------------------------"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.WriteLine("-----------------------------------------------------"); var tv = new TV("Living room"); var hottub = new Hottub(); var stereoOn = new StereoOnCommand(stereo); var tvOn = new TVOnCommand(tv); var hottubOn = new HottubOnCommand(hottub); var tvOff = new TVOffCommand(tv); var hottubOff = new HottubOffCommand(hottub); ICommand[] partyOn = { livingRoomLightOn, stereoOn, tvOn, hottubOn }; ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff }; var partyOnMacro = new MacroCommand(partyOn); var 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); remoteControl.UndoButtonWasPushed(); }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(); Stereo livingRoomStereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOnCommand = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOffCommand = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOnCommand = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOffCommand = new LightOffCommand(kitchenLight); CeilingFanOnCommand livingRoomCeilingFanOnCommand = new CeilingFanOnCommand(livingRoomCeilingFan); CeilingFanOffCommand livingRoomCeilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); GarageDoorUpCommand garageDoorUpCommand = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garageDoor); StereoWithCDCommand livingRoomStereoWithCDCommand = new StereoWithCDCommand(livingRoomStereo); StereoOffCommand livingRoomStereoOffCommand = new StereoOffCommand(livingRoomStereo); // MAIN //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); //remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand); //remoteControl.SetCommand(2, livingRoomCeilingFanOnCommand, livingRoomCeilingFanOffCommand); //remoteControl.SetCommand(3, livingRoomStereoWithCDCommand, livingRoomStereoOffCommand); //Console.WriteLine(remoteControl.ToString()); //Console.ReadLine(); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(1); //remoteControl.OffButtonWasPushed(1); //remoteControl.OnButtonWasPushed(2); //remoteControl.OffButtonWasPushed(2); //remoteControl.OnButtonWasPushed(3); //remoteControl.OffButtonWasPushed(3); //Console.ReadLine(); // UNDO //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine(remoteControl.ToString()); //remoteControl.UndoButtonWasPushed(); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(0); //Console.WriteLine(remoteControl.ToString()); //remoteControl.UndoButtonWasPushed(); //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(livingRoomCeilingFan); //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(livingRoomCeilingFan); //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(livingRoomCeilingFan); //remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); //remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.UndoButtonWasPushed(); //remoteControl.OnButtonWasPushed(1); //remoteControl.UndoButtonWasPushed(); //Console.ReadLine(); // MACRO COMMAND ICommand[] partyOn = new ICommand[] { livingRoomLightOnCommand, garageDoorUpCommand }; ICommand[] partyOff = new ICommand[] { livingRoomLightOffCommand, garageDoorDownCommand }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); Console.ReadLine(); }