编写多路径“故事”的正确方法是什么?流量?

发布于 2024-09-06 04:29:58 字数 785 浏览 4 评论 0原文

我想知道你是否能帮助我。

我正在编写一个游戏(2d),它允许玩家采取多条路线,其中一些是分支/合并 - 甚至可能是循环。游戏的每个部分将决定接下来加载哪个部分。

我将每个部分称为 ISoryElement - 我想知道如何最好地以一种易于更改/配置的方式链接这些元素,同时,可图形化

我将拥有一个引擎/工厂组件,它将根据各种配置选项加载适当的StoryElement

我最初计划为每个 StoryElement 提供一个 NextElement() As ISoryElement 属性和一个 Completed() 事件。当通风口触发时,引擎读取 NextElement 属性以查找下一个 StoryElement

这样做的缺点是,如果我想绘制游戏中的所有路线,我将无法做到 - 我无法确定每个 StoryElement 的所有可能目标。

我考虑了其他几个解决方案,但它们都感觉有点笨拙 - 例如,我需要额外的抽象层吗?即 StoryElementPlayers 或类似的 - 每个都负责将多个 StoryElement 可能是一个 Series 和一个 ChoicePlayer 串在一起,每个负责绘制自己的 StoryElement - 但这只会移动问题上一层。

简而言之,我需要某种方法来模拟简单但动态的工作流程(但我宁愿不实际使用 WWF)。这么简单的事情有模式吗?我设法找到的所有内容都与更高级的控制流(并行处理等)有关

I wonder if you can help me.

I'm writing a game (2d) which allows players to take multiple routes, some of which branch/merge - perhaps even loop. Each section of the game will decide which section is loaded next.

I'm calling each section an IStoryElement - And I'm wondering how best to link these elements up in a way that is easily changed/configured and at the same time, graphable

I'm going to have an engine/factory assembly which will load the appropriate StoryElement(s) based on various config options.

I initially planned to give each StoryElement a NextElement() As IStoryElement property and a Completed() event. When the vent fires, the engine reads the NextElement property to find the next StoryElement.

The downside to this is that if I ever wanted to graph all the routes through the game, I would be unable to - I couldn't determine all possible targets for each StoryElement.

I considered a couple of other solutions but they all feel a little clunky - eg Do I need an additional layer of abstraction? ie StoryElementPlayers or similar - Each one would be responsible for stringing together multiple StoryElement perhaps a Series and a ChoicePlayer with each responsible for graphing its own StoryElement - But this will just move the problem up a layer.

In short, I need some way of emulating a simple but dynamic workflow (but I'd rather not actually use WWF). Is there a pattern for something this simple? All the ones I've managed to find relate to more advanced control flow (parallel processing, etc.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

败给现实 2024-09-13 04:29:58

将 StoryElement 对象视为有向图中的节点可能会有所帮助。图的边缘可以由 StoryElementTransition 对象(或一些类似的名称)表示。 StoryElementTransition 可以包含对要转出的状态、要转入的状态以及可能触发转换的事件的引用。

通过将故事设置为图表,您可以运行有向图遍历算法来确定游戏中所有可能的路线。例如,您可以在事件图上运行深度优先搜索算法,将每个状态和转换推送到堆栈上,并在到达结束状态后打印整个堆栈。

It might help to think about the StoryElement objects as nodes in a directed graph. The edges of the graph could be represented by StoryElementTransition objects (or some similar name). A StoryElementTransition could contain references to the state you want to transition out of, the state you want to transition into, and maybe the event that triggers the transition.

By setting up your story as a graph, you open up the possibility of running a directed graph traversal algorithm to determine all the possible routes through the game. For example, you can run a Depth First Search algorithm on the Event graph, pushing each state and transition on a stack, and printing the entire stack once you reach an end state.

听闻余生 2024-09-13 04:29:58

我知道这个问题有一个公认的答案,也许你已经解决了,但我必须说我最近一直在思考这个问题(“我们应该如何建模以故事情节为中心的游戏?”)以及我得出的结论截至目前:

  • 故事是数据,不应在代码中的任何位置定义它们。

(这同样适用于游戏元素,例如,您不应该拥有 Goblin 类,而是可以从某些敌人数据库加载名为“Goblin”的 Enemy.Creep .)

  • 您能想到的大多数设计都会受到限制或难以扩展。

对我来说,这是设计的黄金法则:让一切可以扩展的东西都可扩展。因此,请建立一个良好的简单类和接口的层次结构,这些类和接口不会做超出其应做的事情,而且会做得很好。因为在某些时候,你可能希望通过杀死森林中的 50 个妖精来触发一个事件,如果你的设计不好,你就必须改编故事或重新构建框架,这都是坏事。

  • 大多数专业游戏都依赖于脚本和引擎。

这是有原因的。首先,如果渲染游戏的代码很小,则可以轻松优化,并且所有故事元素都可以用通用(如 Lua)脚本语言甚至某种自定义符号来定义。因此,您可以在 YAML 或您喜欢的任何内容中定义您的字符。

  • 你不应该在某一点之后触动你的引擎,而专注于故事。

这意味着您将编辑故事文件(数据库?标记?脚本?)并查看它们如何一起运行,同时让您的编译器保持独立。

I know this question has an accepted answer and probably you've settled anyway, but I must say I've been thinking about that lately ("how should we model a storyline-centric game?") and the conclusions I've come to as of now are:

  • Stories are data, they shouldn't be defined anywhere in code.

(The same applies for gameplay elements, for example you shouldn't have a Goblin Class, instead you could load an Enemy.Creep called "Goblin" from some database of enemies.)

  • Most designs you can come up with will be limited or hard to extend.

This is a golden rule of design to me: make everything that may be extended, extensible. So make a good hierarchy of simple classes and interfaces that don't do more than they should and do it well. Because in some point you may want an event to be triggered by killing 50 goblins in the forest and if your design isn't good you'd have to adapt a story or re-factor a framework, both bad things.

  • Most professional games rely on scripting and an engine.

There's a reason to this. First, the code that renders the game can be easily optimized if it's small, and all the story elements can be defined in either a common (like Lua) scripting language or even some custom notation. So you could have your characters defined in YAML or whatever you like.

  • You shouldn't have to touch your engine after a point, and focus on the story.

This means that you'd be editing story files (databases? markups? scripts?) and seeing how they play together, while leaving your compiler alone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文