private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { var remote = new RemoteControl1(); var turnOn = new Light(flashLight); _request = turnOn; _request.LightColor = Colors.ElementAt(Random.Range(0, 5)).Value; remote.Execute(_request); commands.Add(_request); _currentCommandNum = commands.Count; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { Undo(); } if (Input.GetKeyDown(KeyCode.RightArrow)) { Redo(); } }
public void Undo() { if (_currentCommandNum - 1 > 0) { _currentCommandNum--; ILightCommand command = commands[_currentCommandNum - 1]; command.Undo(); } }
public void Redo() { if (_currentCommandNum < commands.Count) { ILightCommand command = commands[_currentCommandNum]; _currentCommandNum++; command.Execute(); } }
public void Execute(ILightCommand command) { command.Execute(); }