Colossal Caves Adventure - 使用 javascript 访问数据源
我一直在考虑创建原始 Colossal Caves Adventure 的 javascript 版本,作为自学语言的一种方式。冒险的原始数据文件可以在这里找到 -
http://jerz.setonhill.edu/if/ crowther/
我希望有经验的 javascripter 可以向我建议存储和访问文本数据文件(只有几百行长)的最佳方法。目前我正在考虑将文本嵌入 html 页面的隐藏元素中并以这种方式访问它,但我知道这缺乏优雅。你有什么想法?
I've been playing around with the idea of creating a javascript version of the original Colossal Caves Adventure, as a way to teach myself the language. The original data file for the adventure can be found here -
http://jerz.setonhill.edu/if/crowther/
I'm hoping an experienced javascripter can suggest to me the best way to store and access the text data file (which is only a few hundred lines long). At the moment I'm thinking of embedding the text in a hidden element in the html page and accessing it that way, but I know that lacks elegance. What are your thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以深入研究并学习 AJAX。 根据需要获取内容正是 AJAX 的强项。 (如果您正在学习 JS,您最终将学习 AJAX)
如果您确实想加载页面上的所有内容,我建议将内容分解为单独的
这可能意味着结果
r
121 是“你遇到了裂缝”You could dive in the deep end and learn AJAX while you're at it. Grabbing content as needed is exactly what AJAX is great at. (If you're learning JS, you will eventually learn AJAX)
If you really want to load all content on page land, I would recommend breaking the content into individual
<input type="hidden"
s. JavaScript grabs their contents very easily, and you can give them descriptiveid
s that will make serving the content more intuitive during programming. e.g.Which could mean result
r
121 is "You come upon a fissure"创建一个分配给变量的 javascript 对象,并将这段代码保存为单独的脚本。将数据和控制代码分开。
因此,也许您有一个名为 advdat.js 的文件,其中包含以下内容:
在加载主程序之前将其加载到其自己的脚本标记中。您的数据现在可在对象 advdat 中使用。
Create a javascript object assigned to a variable and save this piece of code as a separate script. Keeps the data and the control code separate.
So, maybe you have a file called advdat.js that contains this:
Load this in its own script tag before loading the main program. Your data is now available in the object advdat.