Ejemplo n.º 1
0
        public static void Main()
        {
            ICommand          command;
            IElectronicDevice device;
            DeviceButton      button;

            device = new Television();

            command = new TurnOn(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnOff(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnUp(device);
            button  = new DeviceButton(command);
            button.Press();
            button.Press();
            button.Press();

            command = new TurnDown(device);
            button  = new DeviceButton(command);
            button.Press();

            // -----------------------------------

            device = new Radio();

            command = new TurnOn(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnOff(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnUp(device);
            button  = new DeviceButton(command);
            button.Press();
            button.Press();
            button.Press();

            command = new TurnDown(device);
            button  = new DeviceButton(command);
            button.Press();
        }
Ejemplo n.º 2
0
        public static void RunCommand()
        {
            IElectronicDevice newDevice = TVRemote.getDevice();

            TurnTVOn onCommand = new TurnTVOn(newDevice);

            DeviceButton onPressed = new DeviceButton(onCommand);

            onPressed.Press();

            // -------

            TurnTVOff offCommand = new TurnTVOff(newDevice);

            onPressed = new DeviceButton(offCommand);

            onPressed.Press();

            // -------

            TurnTVUp upCommand = new TurnTVUp(newDevice);

            onPressed = new DeviceButton(upCommand);

            onPressed.Press();
        }
Ejemplo n.º 3
0
    void Start()
    {
        Debug.Log("------------------Command Pattern--------------");
        IElectronicDevice device = TVRemove.GetDevice();

        TurnTVOn     onCommand = new TurnTVOn(device);
        DeviceButton onPressed = new DeviceButton(onCommand);

        onPressed.Press();

        // -----------------------

        TurnTVOff offCommand = new TurnTVOff(device);

        onPressed = new DeviceButton(offCommand);
        onPressed.Press();

        TurnVolumeUp volUpCommand = new TurnVolumeUp(device);

        onPressed = new DeviceButton(volUpCommand);
        onPressed.Press();
        onPressed.Press();
        onPressed.Press();

        TurnVolumeDown volDownCommand = new TurnVolumeDown(device);

        onPressed = new DeviceButton(volDownCommand);
        onPressed.Press();

        // -----------------------
        Television tv    = new Television();
        Radio      radio = new Radio();

        List <IElectronicDevice> allDevices = new List <IElectronicDevice>();

        allDevices.Add(tv);
        allDevices.Add(radio);

        TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
        DeviceButton turnThemOff    = new DeviceButton(turnOffDevices);

        turnThemOff.Press();

        // -----------------------
        turnThemOff.PressUndo();
    }
        public static void FirstDemo()
        {
            IElectronicDevice newDevice = TvRemote.getDevice();
            TurnTvOn          onCommand = new TurnTvOn(newDevice);
            DeviceButton      onPressed = new DeviceButton(onCommand);

            onPressed.Press();
            TurnTvOff offcommand = new TurnTvOff(newDevice);

            onPressed = new DeviceButton(offcommand);
            onPressed.Press();


            TurnTvUp upcommand = new TurnTvUp(newDevice);

            onPressed = new DeviceButton(upcommand);
            onPressed.Press();
            onPressed.Press();
            onPressed.Press();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Instantiate a new television.
            Device television = new Television();

            // Create a new command to turn on the television.
            Command turnTelevisionOn = new TurnOn(television);

            // Create a new device button and set the command to
            // turn the television on.
            DeviceButton deviceButton = new DeviceButton(turnTelevisionOn);

            // Press the device button (in turn, executing the command).
            deviceButton.Press();

            // Make a new command to turn off the television, set
            // the command for the device button, and "press" it.
            Command turnTelevisionOff = new TurnOff(television);

            deviceButton.SetCommand(turnTelevisionOff);
            deviceButton.Press();

            Command turnTelevisionVolumeUp = new TurnVolumeUp(television);

            deviceButton.SetCommand(turnTelevisionVolumeUp);

            // Press the button multiple times, then "press" undo.
            deviceButton.Press();
            deviceButton.Press();
            deviceButton.Press();
            deviceButton.PressUndo();
            deviceButton.PressUndo();

            // Instantiate a radio!
            Device radio = new Radio();

            // Make a command to turn the radio off, since we can
            // just use Spotify.
            Command turnRadioOff = new TurnOff(radio);

            deviceButton.SetCommand(turnRadioOff);
            deviceButton.Press();

            Console.ReadKey();
        }