Esempio n. 1
0
        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);
                });
            }
        }
Esempio n. 2
0
        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);
                });
            }
        }