Example #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Stream gameFile;
            string storyName;

            if (args.Length > 0)
            {
                if (!File.Exists(args[0]))
                {
                    MessageBox.Show("File not found: " + args[0]);
                    return;
                }

                try
                {
                    gameFile = new FileStream(args[0], System.IO.FileMode.Open, FileAccess.Read);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                storyName = Path.GetFileName(args[0]);
            }
            else
            {
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.Title = "Select Game File";
                    dlg.Filter = "Supported Z-code files (*.z5;*.z8;*.zblorb;*.zlb)|*.z5;*.z8;*.zblorb;*.zlb|All files (*.*)|*.*";
                    dlg.CheckFileExists = true;
                    if (dlg.ShowDialog() != DialogResult.OK)
                        return;

                    try
                    {
                        gameFile = dlg.OpenFile();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error Loading Game");
                        return;
                    }
                    storyName = Path.GetFileName(dlg.FileName);
                }
            }

            using (GlkIO io = new GlkIO(args, storyName))
            {
            #if !DEBUG
                try
                {
            #endif
                    try
                    {
                        ZMachine engine = new ZMachine(gameFile, io);
                        engine.Run();
                    }
                    finally
                    {
                        gameFile.Close();
                    }
            #if !DEBUG
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Running Game");
                    return;
                }
            #endif
            }
        }
Example #2
0
        private static string RunAndCollectOutput(ZMachine zm, TestCaseIO io)
        {
            string output = null;

            try
            {
                zm.PredictableRandom = true;
                zm.Run();
                output = io.CollectOutput();
            }
            catch (Exception ex)
            {
                if (output == null)
                    output = io.CollectOutput();

                output += "\n\n*** Exception ***\n" + ex.ToString();
            }

            return output;
        }
Example #3
0
        static int Main(string[] args)
        {
            try
            {
                Console.Title = "ConsoleZLR";

                Stream gameStream = null, debugStream = null;
                string gameDir = null, debugDir = null;
                string fileName = null, commandFile = null;
                DisplayType displayType = DisplayType.FullScreen;
                bool debugger = false, predictable = false;
                bool wait = true;

                if (args.Length >= 1 && args[0].Length > 0)
                {
                    int n = 0;

                    bool parsing = true;
                    do
                    {
                        switch (args[n].ToLower())
                        {
                            case "-commands":
                                if (args.Length > n + 1)
                                {
                                    commandFile = args[n + 1];
                                    n += 2;
                                    if (args.Length <= n)
                                        return Usage();
                                }
                                else
                                    return Usage();
                                break;
                            case "-dumb":
                                n++;
                                displayType = DisplayType.Dumb;
                                break;
                            case "-dumb2":
                                n++;
                                displayType = DisplayType.DumbBottomWinOnly;
                                break;
                            case "-debug":
                                n++;
                                debugger = true;
                                break;
                            case "-predictable":
                                n++;
                                predictable = true;
                                break;
                            case "-nowait":
                                n++;
                                wait = false;
                                break;
                            default:
                                parsing = false;
                                break;
                        }
                    } while (parsing);

                    gameStream = new FileStream(args[n], FileMode.Open, FileAccess.Read);
                    gameDir = Path.GetDirectoryName(Path.GetFullPath(args[n]));
                    fileName = Path.GetFileName(args[n]);

                    if (args.Length > n + 1)
                    {
                        debugStream = new FileStream(args[n + 1], FileMode.Open, FileAccess.Read);
                        debugDir = Path.GetDirectoryName(Path.GetFullPath(args[n + 1]));
                    }
                }
                else
                {
                    return Usage();
                }

                IZMachineIO io;

                switch (displayType)
                {
                    case DisplayType.Dumb:
                        io = new DumbIO(false, commandFile);
                        break;

                    case DisplayType.DumbBottomWinOnly:
                        io = new DumbIO(true, commandFile);
                        break;

                    case DisplayType.FullScreen:
                        ConsoleIO cio = new ConsoleIO(fileName);
                        if (commandFile != null)
                        {
                            cio.SuppliedCommandFile = commandFile;
                            cio.HideMorePrompts = true;
                        }
                        io = cio;
                        break;

                    default:
                        throw new NotImplementedException();
                }

                ZMachine zm = new ZMachine(gameStream, io);
                zm.PredictableRandom = predictable;
                if (commandFile != null)
                    zm.ReadingCommandsFromFile = true;
                if (debugStream != null)
                    zm.LoadDebugInfo(debugStream);

                if (debugger)
                {
                    List<string> sourcePath = new List<string>(3);
                    if (debugDir != null)
                        sourcePath.Add(debugDir);
                    sourcePath.Add(gameDir);
                    sourcePath.Add(Directory.GetCurrentDirectory());

                    DebuggerLoop(zm, sourcePath.ToArray());
                }
                else
                {
            #if DEBUG
                    zm.Run();
            #else
                try
                {
                    zm.Run();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            #endif
                    if (wait)
                    {
                        Console.WriteLine("Press any key to exit...");
                        Console.ReadKey(true);
                    }
                }
                return 0;
            }
            catch (Exception ex)
            {
                return Error(ex.Message + " (" + ex.GetType().Name + ")");
            }
        }
Example #4
0
			public void Main()
			{
				try
				{	// will block on zm.Run() until the story file completes
					Stream gameStream = new FileStream(m_storyFile, FileMode.Open, FileAccess.Read);
					DumbIO io = new DumbIO(this);
					ZMachine zm = new ZMachine(gameStream, io);
					zm.Run(); 
				}
                catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); }
				m_stopped = true;
				return;
			}