Exemple #1
0
        static void Main()
        {
            var remote = new RemoteControl();

            var light  = new Light();
            var stereo = new Stereo();

            var lightOnCommand    = new LightOnCommand(light);
            var lightOffCommand   = new LightOffCommand(light);
            var stereoOnCommand   = new StereoOnCommand(stereo);
            var stereoOffCommand  = new StereoOffCommand(stereo);
            var stereoOnCdCommand = new StereoOnCdCommand(stereo);

            remote.OnCommands[0]  = lightOnCommand;
            remote.OnCommands[1]  = stereoOnCommand;
            remote.OnCommands[2]  = stereoOnCdCommand;
            remote.OffCommands[0] = lightOffCommand;
            remote.OffCommands[1] = stereoOffCommand;

            remote.OnButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            Console.WriteLine(remote);
            remote.OffButtonWasPushed(0);
            remote.OffButtonWasPushed(1);
            remote.UndoButtonPushed();
        }
        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();
        }