private static void Run(Options options) { try { if (!File.Exists(options.InputFile)) { Console.Error.WriteLine($"Input file `{options.InputFile}` does not exist"); return; } IDeviceNetwork network = new ConsoleInputDeviceNetwork(); if (options.Client != null) { network = new HttpClientDeviceNetwork(options.Client); } if (options.HostPort != null) { network = new HttpHostDeviceNetwork(options.HostPort.Value); } var lines = 0; var st = new MachineState(network, options.MaxLineNumber); var pc = 0; while (pc <= options.MaxLineNumber) { // Read the next line to execute from the file var line = ReadLine(options.InputFile, pc); Console.WriteLine($"[{pc + 1:00}] {line}"); // Evaluate this line pc = EvaluateLine(line, pc, st); lines++; // Print machine state Console.Title = $"Elapsed Game Time: {TimeSpan.FromMilliseconds(200 * lines).TotalSeconds.ToString(CultureInfo.CurrentCulture)}s"; Console.WriteLine("State:"); foreach (var(key, value) in st) { Console.WriteLine($" | {key} = {value}"); } Console.WriteLine(); // Pause until made to continue Console.Write("Press F5 to continue"); while (Console.ReadKey(true).Key != ConsoleKey.F5) { } Console.CursorLeft = 0; Console.WriteLine(string.Join("", Enumerable.Repeat('=', Console.WindowWidth))); } } catch (Exception e) { Error(() => { Console.WriteLine(); Console.WriteLine("Fatal Exception:"); Console.Error.WriteLine(e); }); } }
private static void Run(Options options) { try { if (!File.Exists(options.InputFile)) { Console.Error.WriteLine($"Input file `{options.InputFile}` does not exist"); return; } IDeviceNetwork network = new ConsoleInputDeviceNetwork(); if (options.Client != null) { network = new HttpClientDeviceNetwork(options.Client); } if (options.HostPort != null) { network = new HttpHostDeviceNetwork(options.HostPort.Value); } var st = new MachineState(network, new DefaultIntrinsics()); var pc = 0; while (pc <= 20) { // Read the next line to execute from the file var line = ReadLine(options.InputFile, pc); Console.WriteLine($"[{pc + 1:00}] {line}"); // Evaluate this line pc = EvaluateLine(line, pc, st); // Print machine state Console.WriteLine("State:"); foreach (var(key, value) in st) { Console.WriteLine($" | {key} = {value}"); } Console.WriteLine(); // Pause until made to continue Console.Write("Press F5 to continue"); while (Console.ReadKey(true).Key != ConsoleKey.F5) { continue; } Console.CursorLeft = 0; Console.WriteLine(string.Join("", Enumerable.Repeat('=', Console.WindowWidth))); } } catch (Exception e) { Error(() => { Console.WriteLine(); Console.WriteLine("Fatal Exception:"); Console.Error.WriteLine(e); }); } }
private static void Run(Options options) { try { if (string.IsNullOrWhiteSpace(options.InputFile) || !File.Exists(options.InputFile)) { Console.Error.WriteLine($"Input file `{options.InputFile}` does not exist"); return; } IDeviceNetwork network = new ConsoleInputDeviceNetwork(options.SaveOutputs, options.EndProgramVar); var endvar = network.Get(options.EndProgramVar); var st = new MachineState(network, options.MaxLineNumber); var pc = 0; while (pc <= options.MaxLineNumber) { if (endvar.Value.ToBool()) { break; } // Read the next line to execute from the file var line = ReadLine(options.InputFile, pc); Console.WriteLine($"[{pc + 1:00}] {line}"); // Evaluate this line pc = EvaluateLine(line, pc, st); // Print machine state DisplayState(st); Console.WriteLine(); if (options.Auto) { // Delay execution of the next line System.Threading.Thread.Sleep(options.Delay); // Press F5 to halt execution if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F5) { break; } } else { // Pause until user presses F5 Console.Write("Press F5 to continue"); while (Console.ReadKey(true).Key != ConsoleKey.F5) { } Console.CursorLeft = 0; Console.WriteLine(new string(' ', Console.WindowWidth)); } Console.WriteLine(); } } catch (Exception e) { Console.WriteLine(); DrawLine("Fatal Exception:", ConsoleColor.Red); DrawLine(e.ToString(), ConsoleColor.Red); } }