0
branches =
branch0:
  name: "Start" 
  text: "This is a wall of text. #1 {Terra: Hello there! My name is Terra! What's yours?} You find your desperation outweighing Cora’s vague warning. You feel miserable, paranoid, and your skin grows more raw and drenched by the minute. This is the fourth wall of text. This is the fifth wall of text. {Terra: My you're cute!} This is the sixth wall of text."
  options: 
    branch1: "Bad"
    branch2: "Good"
branch1:
  name: "Bad Intro"
  text: "You're a bad person!"
  options:
    branch3: "To Gate"
branch2:
  name: "Good Intro"
  text: "You've done good things!"
  options:
    branch3: "To Gate"

所以我正在开发一款基于文本的游戏。主要的分支路径被分成对象,故事文本是一个叫做“文本”的属性;主要的游戏逻辑涉及读取“text:”属性中的巨大字符串并将其写入 HTML 文档。

为了便于阅读,有没有什么办法可以从单独的文件中读取我的文本,并以某种方式让内容显示为我的“文本:”属性的字符串?在这个项目上工作变得越来越混乱和困难,一个 7000 多个单词的故事把我的主要代码弄得乱七八糟。

4

1 回答 1

1

您应该将游戏数据提取到一个文件或一组文件中。这可以是 JSON(完整的对话树/每个分支的文件)或只是文本(例如从 加载分支的文本branch1text/branch1.txt

一般来说,让您的游戏数据富有表现力是个好主意,这样您就可以将数据和代码分开,并从一组数据文件(即 JSON 文件)中定义游戏的大部分行为。除了使您的游戏更加健壮之外,它还允许非程序员在不更改源代码的情况下制作内容并进行尝试。

于 2016-07-13T08:56:38.287 回答