Example #1
0
        static void Main(string[] args)
        {
            var tv      = new TV();
            var remote  = new Remote();
            var command = new CommandOnTV(tv);

            remote.SetCommand(command);
            remote.PressButton();
            remote.PressUndo();
        }
Example #2
0
        static void Main(string[] args)
        {
            Pult    invoker         = new Pult();
            TV      reciver         = new TV();
            Command concreteCommand = new Command(reciver);

            invoker.SetCommand(concreteCommand);
            invoker.PressButton();
            invoker.PressUndo();
        }
Example #3
0
        static void Main(string[] args)
        {
            Pult pult = new Pult();
            TV   tv   = new TV();

            pult.SetCommand(new TVOnCommand(tv));
            pult.PressButton();
            pult.PressUndo();

            Console.Read();
        }
Example #4
0
        static void Main(string[] args)
        {
            Pult pult = new Pult();
            TV   tv   = new TV();

            pult.SetCommand(new TVonCommand(tv));
            pult.PressButton(); //включение
            pult.PressUndo();   //выключение

            Console.ReadKey();
        }
Example #5
0
        static void Main(string[] args)
        {
            TV   tv   = new TV();
            Pult pult = new Pult(new TVOnCommand(tv));

            pult.PressDoButton();
            pult.PressUndoButton();
            Console.ReadKey();
            //pult can send any command to tv at the same time pult know nothing about just like tv
            //know nothing about pult
            //thus we have flexible system where all the commands are stored in one class
        }
Example #6
0
        static void Main(string[] args)
        {
            TV     tv     = new TV();
            Remote remote = new Remote();

            remote.SetCommand(new TVOnCommand(tv));

            remote.PressButton();
            remote.PressUndo();

            Console.Read();
        }
Example #7
0
        public static void Main(string[] args)
        {
            // Объект пульта - инициатора комманды.
            Pult pult = new Pult();
            // Принимающая сторона комманды.
            TV tv = new TV();

            // Устанавливаем комманду и кому она будет отправляться.
            pult.SetCommand(new TVOnCommand(tv));
            // Через нашу абстракцию пульт посылаем команды, нашей абстракции телевизору.
            pult.PressButton();
            pult.PressUndo();

            Console.Read();
        }
Example #8
0
        static void Main(string[] args)
        {
            Pult pult = new Pult();
            TV   tv   = new TV();

            pult.SetCommand(new TVOnCommand(tv));
            pult.PressButton();
            pult.PressUndo();

            Microwave microwave = new Microwave();

            pult.SetCommand(new MicrowaveCommand(microwave, 5000));
            pult.PressButton();

            Console.Read();
        }
Example #9
0
        static void Main(string[] args)
        {
            var tv = new TV();
            var airConditioning = new AirConditioning();

            var tvOnCommand     = new TvOnCommand(tv);
            var airStartCommand = new AirConditioningStartCommand(airConditioning, 21d);

            var pult = new Pult
            {
                BlueBtnCommand = tvOnCommand,
                RedBtnCommand  = airStartCommand
            };

            pult.BlueBtnPress();
            pult.RedButtonPress();

            Console.ReadKey();
        }
Example #10
0
        static void Main(string[] args)
        {
            TV        tv     = new TV();
            Volume    volume = new Volume();
            MultiPult mPult  = new MultiPult();

            mPult.SetCommand(0, new TVOnCommand(tv));
            mPult.SetCommand(1, new VolumeCommand(volume));
            mPult.PressButton(0);
            mPult.PressButton(1);
            mPult.PressButton(1);
            mPult.PressButton(1);
            mPult.PressUndoButton();
            mPult.PressUndoButton();
            mPult.PressUndoButton();
            mPult.PressUndoButton();

            Console.Read();
        }
Example #11
0
        private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Title           = "Command";

            var remoteControl = new RemoteControl();
            var tv            = new TV();

            remoteControl.SetCommand(new TVOnCommand(tv));
            remoteControl.PressButton();
            remoteControl.PressUndo();

            var microwave = new Microwave.Microwave();

            // 5000 - время нагрева пищи
            remoteControl.SetCommand(new MicrowaveCommand(microwave, 5000));
            remoteControl.PressButton();

            Console.ReadKey();
        }
Example #12
0
        static void Main(string[] args)
        {
            Pult pult = new Pult();
            TV   tv   = new TV();

            pult.SetCommand(new TVOnCommand(tv));
            pult.PressButton();
            pult.PressUndo();

            Microwave microwave = new Microwave();

            pult.SetCommand(new MicrowaveCommand(microwave, 5000));
            pult.PressButton();

            MacroCommand macro = new MacroCommand(new List <ICommand>()
            {
                new TVOnCommand(tv), new MicrowaveCommand(microwave, 5000)
            });

            pult.SetCommand(macro);
            pult.PressButton();
        }
Example #13
0
 public Command(TV _tv)
 {
     tv = _tv;
 }
Example #14
0
 public TvOffCommand(TV tv)
 {
     this._tv = tv;
 }
Example #15
0
 public TVOnCommand(TV tvSet)
 {
     tv = tvSet;
 }
        public static void Main()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      livingRoomLight = new Light("Living room");
            Light      kitchenLight    = new Light("Kitchen Light");
            CeilingFan ceilingFan      = new CeilingFan("Living room");
            GarageDoor garageDoor      = new GarageDoor();
            Stereo     stereo          = new Stereo("Living room");
            TV         tv     = new TV("Living room");
            Hottub     hottub = new Hottub();

            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            LightOnCommand  kitchenLightOn  = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

            CeilingFanOnCommand  ceilingFanHigh = new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff  = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            TVOnCommand  tvOn  = new TVOnCommand(tv);
            TVOffCommand tvOff = new TVOffCommand(tv);

            HottubOnCommand  hottubOn  = new HottubOnCommand(hottub);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

            ICommand[] partyOn  = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff };

            //TODO: deal with the Macrocommand name
            Macrocommand partyOnMacro  = new Macrocommand(partyOn);
            Macrocommand partyOffMacro = new Macrocommand(partyOff);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);
            remoteControl.SetCommand(4, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPressed(0);
            remoteControl.OffButtonWasPressed(0);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(1);
            remoteControl.OffButtonWasPressed(1);
            remoteControl.OnButtonWasPressed(2);
            remoteControl.OffButtonWasPressed(2);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(3);
            remoteControl.OffButtonWasPressed(3);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OnButtonWasPressed(4);
            Console.WriteLine("Party is on!");
            remoteControl.OffButtonWasPressed(4);
            Console.WriteLine("Party is over");


            Console.ReadLine();
        }
Example #17
0
 public CommandOnTV(TV tvSet)
 {
     tv = tvSet;
 }
Example #18
0
        static void Main(string[] args)
        {
            RemoteControl remote     = new RemoteControl();
            CeilingFan    ceilingFan = new CeilingFan("Living Room");
            //Light livingRoomLight = new Light("Living Room");
            //Light kitchenLight = new Light("Kitchen");
            //GarageDoor garageDoor = new GarageDoor();
            //Stereo stereo = new Stereo("Living room");
            //AirCondition airCondition = new AirCondition();
            //
            //LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            //LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);
            //
            //LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
            //LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);
            //
            //CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan);
            //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);
            //
            //GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor);
            //GarageDoorCloseCommand garageDoorOff = new GarageDoorCloseCommand(garageDoor);
            //
            //StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            //StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            //
            //AirConditionOnCommand airCondtionOnCommand = new AirConditionOnCommand(airCondition);
            //AirconditionOffCommand airCondtionOffCommand = new AirconditionOffCommand(airCondition);
            //
            //remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            //remote.SetCommand(1, kitchenLightOn, kitchenLightOff);
            //remote.SetCommand(2, ceilingFanOn, ceilingFanOff);
            //remote.SetCommand(3, stereoOnWithCD, stereoOff);
            //remote.SetCommand(4, airCondtionOnCommand, airCondtionOffCommand);
            //
            //Console.WriteLine(remote);
            //
            //remote.OffButtonWasPressed(0);
            //remote.OffButtonWasPressed(1);
            //remote.OffButtonWasPressed(2);
            //remote.OffButtonWasPressed(3);
            //remote.OffButtonWasPressed(4);
            //Console.WriteLine();
            //remote.OnButtonWasPressed(0);
            //remote.OnButtonWasPressed(1);
            //remote.OnButtonWasPressed(2);
            //remote.OnButtonWasPressed(3);
            //remote.OnButtonWasPressed(4);

            // CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            // CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            // CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan);
            // CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);
            //
            // remote.SetCommand(0, ceilingFanLow, ceilingFanOffCommand);
            // remote.SetCommand(1, ceilingFanMedium, ceilingFanOffCommand);
            // remote.SetCommand(2, ceilingFanHigh, ceilingFanOffCommand);
            //
            // remote.OnButtonWasPressed(0);
            // remote.OnButtonWasPressed(1);
            // remote.OnButtonWasPressed(2);
            //
            // Console.WriteLine(remote);
            //
            // remote.OffButtonWasPressed(1);
            // remote.UndoButtonWasPressed();


            Light  light  = new Light("Living room");
            TV     tv     = new TV();
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            LightOnCommand        lightOnCommand  = new LightOnCommand(light);
            TvOnCommand           tvOnCommand     = new TvOnCommand(tv);
            StereoOnWithCDCommand stereoOnCommand = new StereoOnWithCDCommand(stereo);
            HottubOnCommand       hottunOnCommand = new HottubOnCommand(hottub);

            LightOffCommand  lightOffCommand  = new LightOffCommand(light);
            TvOffCommand     tvOffCommand     = new TvOffCommand(tv);
            StereoOffCommand stereoffCommand  = new StereoOffCommand(stereo);
            HottubOffCommand hottunOffCommand = new HottubOffCommand(hottub);

            ICommand[] partyOn =
            {
                lightOnCommand,
                tvOnCommand,
                stereoOnCommand,
                hottunOnCommand
            };
            ICommand[] partOff =
            {
                lightOffCommand,
                tvOffCommand,
                stereoffCommand,
                hottunOffCommand
            };

            MacroCommand OnMacro  = new MacroCommand(partyOn);
            MacroCommand OffMacro = new MacroCommand(partOff);

            remote.SetCommand(0, OnMacro, OffMacro);
            Console.WriteLine(remote);
            remote.OnButtonWasPressed(0);
            remote.UndoButtonWasPressed();
            remote.OnButtonWasPressed(0);
        }
Example #19
0
 public TVOnCommand(TV tv)
 {
     _tv = tv;
 }
Example #20
0
 public TVOnCommand(TV tv1)
 {
     tv = tv1;
 }
Example #21
0
 public TvOnComand(TV tv)
 {
     this._tv = tv;
 }