Esempio n. 1
0
 public void Start(FileStream file)
 {
     zMachine.LoadFile(file);
     zMachineThread      = new Thread(() => zMachine.Run());
     zMachineThread.Name = channel.Id.ToString();
     zMachineThread.Start();
 }
Esempio n. 2
0
 protected override void Run()
 {
     //Console.WriteLine("Specify game path:");
     //string fileName = string.Empty;
     try
     {
         //fileName = Console.ReadLine();
         //if (fileName == "ls")
         //{
         //    foreach (var dir in Directory.GetFiles("0:\\"))
         //    {
         //        Console.WriteLine($"0:\\{dir}");
         //    }
         //}
         //else
         //{
         var machine = new ZMachine(GameData);
         machine.Run();
         //}
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ZMachine zMachine = new ZMachine(new ConsoleIO());

            FileStream fs = File.OpenRead(@"zork1.dat");

            zMachine.LoadFile(fs);
            zMachine.Run();
        }
Esempio n. 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;
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            byte[] data;
            using (var reader = new FileStream("..\\..\\..\\..\\ZKernel\\ZORK1.DAT", FileMode.Open))
            {
                data = new byte[reader.Length];
                reader.Read(data, 0, data.Length);
                reader.Close();
                reader.Dispose();
            }

            var machine = new ZMachine(data);

            machine.Run();

            Console.ReadKey();
        }
Esempio n. 6
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);
        }
Esempio n. 7
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 + ")"));
            }
        }
Esempio n. 8
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
            }
        }
Esempio n. 9
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            switch (activity.Text)
            {
            case "/reset":
                activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id);
                break;
            }

            BotIO      io       = new BotIO();
            ZMachine   zMachine = new ZMachine(io);
            string     gameFile = Environment.GetEnvironmentVariable("GameFile");
            string     path     = HostingEnvironment.MapPath($"~/Games/{gameFile}");
            FileStream fs       = File.OpenRead(path);

            zMachine.LoadFile(fs);

            BotData data = activity.GetStateClient().BotState.GetUserData(activity.ChannelId, activity.From.Id);

            byte[] state = data.GetProperty <byte[]>("ZState");
            try
            {
                if (state != null)
                {
                    using (MemoryStream ms = new MemoryStream(state))
                        zMachine.RestoreState(ms);
                    zMachine.FinishRead(activity.Text);
                }
            }
            catch (Exception)
            {
                activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id);
            }

            zMachine.Run(true);
            Stream s = zMachine.SaveState();

            using (MemoryStream ms = new MemoryStream())
            {
                s.CopyTo(ms);
                data.SetProperty("ZState", ms.ToArray());
            }

            activity.GetStateClient().BotState.SetUserData(activity.ChannelId, activity.From.Id, data);

            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                // return our reply to the user
                Activity reply = activity.CreateReply(io.Text);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Esempio n. 10
0
        void ExecuteGame(string gameFile, Editor ed)
        {
            var showScore = ed.GetYesOrNo("Show the score as we go?", false);

            if (!showScore.HasValue)
            {
                return;
            }

            var saveCmds = ed.GetYesOrNo("Save commands to file?", false);

            if (!saveCmds.HasValue)
            {
                return;
            }

            var  cmdFile = "";
            bool open    = false;

            if (saveCmds.Value)
            {
                cmdFile = ed.GetFilename("Command file to write", false);
                open    = false;
            }
            else
            {
                var openCmds = ed.GetYesOrNo("Read commands from file?", false);
                if (!openCmds.HasValue)
                {
                    return;
                }

                if (openCmds.Value)
                {
                    cmdFile = ed.GetFilename("Command file to read", true);
                    open    = true;
                }
            }

            try
            {
                var gameStream =
                    new FileStream(gameFile, FileMode.Open, FileAccess.Read);

                var io = new AutoCADIONodeMap(ed, showScore.Value, cmdFile);
                var zm = new ZMachine(gameStream, io);
                if (!String.IsNullOrWhiteSpace(cmdFile))
                {
                    if (open)
                    {
                        zm.ReadingCommandsFromFile = true;
                    }
                    else
                    {
                        zm.WritingCommandsToFile = true;
                    }
                }
                zm.PredictableRandom = false;
                zm.Run();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("{0} ({1})", ex.Message, ex.GetType().Name);
            }
        }