public void Add(int vlt) { if (OnOff == true) { techvolt += vlt; persVolt += vlt; if (techvolt < tech_power) { TurnOn?.Invoke($"Мощность увеличина на {vlt}"); TurnOn?.Invoke($"(В настоящий момент мощность техники {techvolt})"); } else { Console.WriteLine("Техника сломалась"); } if (persVolt < person_power) { TurnOn?.Invoke($"(В настоящий момент мощность человека {persVolt})"); } else { Console.WriteLine("Человек сломался"); } } else { Console.WriteLine("Вы не включили технику"); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { var remote = new RemoteControl(); var turnOn = new TurnOn(bulb); var turnOff = new TurnOff(bulb); bulb.toggle = !bulb.toggle; _request = bulb.toggle ? (ICommand)turnOn : turnOff; remote.Execute(_request); commands.Add(_request); _currentCommandNum = commands.Count; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { Undo(); } if (Input.GetKeyDown(KeyCode.RightArrow)) { Redo(); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.O)) { var TurnTV = new TurnOn(TV); invoker.SetCommand(TurnTV); invoker.ExecuteCommand(); var TurnRadio = new TurnOn(Radio); invoker.SetCommand(TurnRadio); invoker.ExecuteCommand(); } if (Input.GetKeyDown(KeyCode.F)) { var TurnTV = new TurnOff(TV); invoker.SetCommand(TurnTV); invoker.ExecuteCommand(); var TurnRadio = new TurnOff(Radio); invoker.SetCommand(TurnRadio); invoker.ExecuteCommand(); } if (Input.GetKeyDown(KeyCode.K)) { var TurnOffAll = new Kill(AllReceivers); invoker.SetCommand(TurnOffAll); invoker.ExecuteCommand(); } }
public static Device TurnOn(IEventMetadata eventMetadata, IEventStore eventStore, Commands.Device.TurnOnCommand cmd) { var turnOnDeviceCommand = new TurnOn(cmd.DeviceId, cmd.Level); var commandBus = CommandBus.Instance; commandBus.Execute(turnOnDeviceCommand); var device = new Device(cmd.DeviceId, eventMetadata, eventStore, cmd.Level); return(device); }
static void Main(string[] args) { var bulb = new Bulb(); var turnOn = new TurnOn(bulb); var turnOff = new TurnOff(bulb); var remote = new RemoteControl(); remote.Submit(turnOn); // Bulb has been lit! remote.Submit(turnOff); // Darkness! Console.ReadLine(); }
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(); }
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(); }
public static Dictionary <string, object> ToParameters(this TurnOn on, Component component, IEnumerable <IDevice> deviceId) { switch (component) { case Component.Light: return(new Dictionary <string, object>() .Add(deviceId) .AddIfValue("brightness", on.Level, level => (int)(level * 255)) .AddIfValue("rgb_color", on.Color) .AddIfValue("transition", on.Duration)); case Component.Switch: return(new Dictionary <string, object>() .Add(deviceId)); default: throw new NotSupportedException($"Component '{component}' does not support command TurnOn, but on or more device tries to use it ({deviceId.Select(d => d.Id.ToString()).JoinBy(", ")})"); } }
public static Dictionary <string, object> ToParameters(this TurnOn on, Domain domain, IEnumerable <IDevice> devices, out TimeSpan?transition) { transition = null; switch (domain) { case Domain.Light: return(new Dictionary <string, object>() .Add(devices) .AddIfValue("brightness", on.Level, level => (int)(level * 255)) .AddIfValue("rgb_color", on.Color) .AddIfValue("transition", on.Duration, out transition) .AddIfValue("effect", on.Effect)); case Domain.InputBoolean: case Domain.Switch: case Domain.Fan: return(new Dictionary <string, object>() .Add(devices)); default: throw new NotSupportedException($"Domain '{domain}' does not support command TurnOn, but one or more device tries to use it ({devices.Select(d => d.Id.ToString()).JoinBy(", ")})"); } }
protected void OnTurnOn() { TurnedOn = true; TurnOn?.Invoke(this, "Turned on"); }
public void Start(int voltage) { TurnOn?.Invoke(voltage); }
public CellLogic(TurnOn turnOn, TurnOff turnOff, bool cellOn) { this.turnOn = turnOn; this.turnOff = turnOff; this.cellOn = cellOn; }
public void Handle(TurnOn message) { //Validate //Process }