public void Run() { _run = true; while (_run) { _commandInput.AwaitInput(); _repairDroid.ExecuteInstruction(); } }
public RepairDroid(IntCodeStateMachine cpu, ICommandInput commandInput) { _cpu = cpu; _commandInput = commandInput; _commandInput.InputReceived += (_, v) => { var cmd = (MovementCommand)v; if (v < 1 || v > 4) { throw new Exception("Wrong input value"); } _cpu.SetInput((int)cmd); }; _cpu.OnOutput += (_, o) => { _lastOutput = (RepairDroidStatusCode)o; OnReply?.Invoke(this, _lastOutput); commandInput.AwaitInput(); }; }