static void Main(string[] args) { //Invoker RemoteController controller = new RemoteController(); //Receiver Robot robot = new Robot(0, 0); //Command AbstractCommand move1 = new CmdMove(robot); AbstractCommand move2 = new CmdMove(robot); AbstractCommand move3 = new CmdMove(robot); Console.WriteLine("-----Orginal state of robot----"); Console.WriteLine("Angle: {0}, Distance:{1}", robot.Angle, robot.Distance); controller._queue.Enqueue(move1); controller._queue.Enqueue(move2); controller._queue.Enqueue(move3); Console.WriteLine("-----After moving----"); controller.Execute(); Console.WriteLine("Angle: {0}, Distance:{1}", robot.Angle, robot.Distance); Console.WriteLine("-----After undoing last----"); controller.UndoLast(); Console.WriteLine("Angle: {0}, Distance:{1}", robot.Angle, robot.Distance); Console.WriteLine("-----After Undoing----"); controller.UnDoAll(); Console.WriteLine("Angle: {0}, Distance:{1}", robot.Angle, robot.Distance); Console.ReadKey(); }
static void Main(string[] args) { //Existing stuff in the house Light bedRoomLights = new Light(); AirConditioner acForEntireHouse = new AirConditioner(); //Create the ON commands LightOn turnBedRoomLightsOn = new LightOn(bedRoomLights); AirConditionerOn turnOnAc = new AirConditionerOn(acForEntireHouse); //Create the OFF commands LightOff turnBedRoomLightOff = new LightOff(bedRoomLights); AirConditionerOff turnOffAc = new AirConditionerOff(acForEntireHouse); //Add the ON to the remote RemoteController remote = new RemoteController(); remote.InsertNewOnCommand(turnBedRoomLightsOn); remote.InsertNewOnCommand(turnOnAc); //Add the OFF to the remote remote.InsertNewOffCommand(turnBedRoomLightOff); remote.InsertNewOffCommand(turnOffAc); //Turn on the lights and AC remote.PressButtonOn(0); remote.PressButtonOn(1); //Turn off the lights and AC remote.PressButtonOff(0); remote.PressButtonOff(1); }
static void Main(string[] args) { // Existing stuff in the house Light bedRoomLights = new Light(); AC acForTheHouse = new AC(); // CREATE the On cmd LightOn trunbedRoomLightsOn = new LightOn(bedRoomLights); ACOn trunOnAC = new ACOn(acForTheHouse); // CREATE the off cmd LightOff trunbedRoomLightsOff = new LightOff(bedRoomLights); ACOff trunOffAC = new ACOff(acForTheHouse); // add the On / off to the Remote RemoteController remote = new RemoteController(); remote.InsertNewOnCommand(trunbedRoomLightsOn); remote.InsertNewOnCommand(trunOnAC); remote.InsertNewOffCommand(trunbedRoomLightsOff); remote.InsertNewOffCommand(trunOffAC); // turn on the Light and AC remote.PressButonOn(0); remote.PressButonOn(1); // turn off both remote.PressButonOff(0); remote.PressButonOff(1); }
static void Main(string[] args) { TV sonyTV = new SonyTVFactory().Create(); TVCommand disCmd = new DisplayCommand(sonyTV); TVCommand moveNextCmd = new MoveNextCommand(sonyTV); TVCommand movePreCmd = new MovePreviousCommand(sonyTV); TV philipsTv = new PhilipsTVFactory().Create(); TVCommand movePreCmd_philips = new MovePreviousCommand(philipsTv); RemoteController rc = new RemoteController(disCmd, moveNextCmd, movePreCmd_philips); rc.Display(); rc.MoveNextChannel(); rc.MovePreviousChannel(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //调用端 var client = new RemoteController(); //灯(接收者) var light = new Light(); var command1 = new LightOnCmd(light); var command2 = new LightOffCmd(light); client.AddCommand(command1); client.AddCommand(command2); client.ExcuteCommands(); Console.ReadLine(); }