RPG(角色扮演游戏)的类图示例

发布于 2024-07-29 11:28:44 字数 219 浏览 2 评论 0 原文

有谁知道在哪里可以找到 RP 游戏开发的类图示例? 类似于这里的东西会非常有用。 我并不是在寻找可以盲目复制的东西,而是寻找不同的例子,这些例子描绘了我在尝试用铅笔记下自己的课程时发现的问题的各种解决方案。

Does anyone know where I can find examples of class diagrams for RP game development? Something similar to here would be quite useful. I'm not looking for things I can slavishly copy, but just for different examples that diagram various solutions to the problems I'm discovering as I try and pencil down my own classes.

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

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

发布评论

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

评论(7

酸甜透明夹心 2024-08-05 11:28:44

我从 GameDev.net 认识 Emmanuel Deloget,但我不确定我是否会选择使用他那里的层次结构! 继承太多,灵活性不够。

如果我正在编写一个基于文本的角色扮演游戏(就像我过去所做的那样),它看起来有点像这样(遗憾的是,我没有时间为它绘制图表):

  • 生物、房间和物品派生
    来自 WorldEntity,与 WorldEntity
    以组合方式排列的对象
    结构,因此物品可以存在于其中
    由生物携带的其他物品,
    存在于房间内的人。 实施
    WorldEntities 的访问者模式
    可能会运作良好。
  • CreatureType 和 ItemType 类
    其中包含“类”数据
    个体生物和物品
    实例,引用回它们的
    相应的“类型”对象。 (例如,基地
    前者的生命值和统计数据,
    当前生命值和瞬态效果
    在后者)。 我可能会将这些实现为
    得到的属性的原型列表
    复制到生物或物品实例时
    他们被创造了。 您可以实现属性
    通过“父”属性继承,以便
    特定的妖精生物实例可能与
    ‘战士妖精’CreatureType,其中包含
    对“通用妖精”CreatureType 的父引用。 等等。
  • 出口由他们的房间拥有,并且是
    一种方式,并详细说明了方向
    旅行、各种通行条件等。
  • 包含相连房间组的区域
    通过某种逻辑组织。
  • 一个 Spawn 类来决定生物在哪里
    并创建 Item 实例(例如哪个房间,
    或在什么坐标),它们何时创建以及
    以什么频率、从什么时间开始
    其中 CreatureTypes 和 ItemTypes。 你可能有
    这里有一些逻辑可以使事情随机化。
  • 法术、技能、能力等。
    全部派生自 Action 基类
    或指定先决条件的接口
    (例如,当前位置、法力值、一些
    技能的学习程度等)。 普通的
    命令和操作也可以放在这里,因为它们
    通常也有某种要求
    (例如,“睡眠”命令要求您不
    已经在睡觉了。)
  • FutureEvent 类本质上是一个
    您推送到优先级队列的回调
    以便将来执行。 您可以使用这些来
    安排战斗回合、法术冷却时间、
    昼夜循环,随心所欲。
  • 名称->值对的哈希/映射/字典
    玩家和物品统计。 不是类型安全的,但是
    稍后您会欣赏到这种灵活性。 在我的
    制作 stats 成员变量的经验是
    可行但不灵活,并且具有专业性
    “属性”类变得复杂
    调试时的噩梦。
  • 包含统计名称的修饰符类型
    和修饰符值(例如+10、+15%)。 这些
    在使用时添加到您的生物中
    (例如,通过法术效果,或通过挥舞
    一件附魔武器)然后被脱掉
    通过定时 FutureEvent 或其他一些事件,例如
    作为正在执行的命令。
  • 特定于游戏的类,例如 PlayerClass 或
    PlayerRace,每个描述一个玩家的职业
    (例如战士、巫师、小偷)或种族(人类、精灵、
    矮人)并设置起始统计值和限制,
    可用技能列表、特殊能力等。
  • 基本玩家界面类会有所不同
    取决于您的实际游戏类型。 你可能会
    有图形游戏的渲染类,或者
    在 MUD 中你可能有一个 Connection 类
    反映到玩家客户端的 TCP 连接。
    尝试将所有游戏逻辑排除在外。
  • 脚本接口。 你的大部分命令、咒语
    生物人工智能可以更快地实现
    一个不错的脚本接口并且可以节省编译时间
    也下来了。 它还允许进行一些很棒的游戏内调试
    和诊断能力。

这将是我使用的基本高级结构。

I know Emmanuel Deloget from GameDev.net but I'm not sure I would choose to use the hierarchy he's got there! Too much inheritance, not enough flexibility.

If I was writing a text-based RPG (as I have done in the past) it would look a bit like this (though I've no time to draw up a diagram for it, sadly):

  • Creatures, Rooms, and Items derived
    from WorldEntity, with WorldEntity
    objects arranged in a Composite
    structure, so items can live within
    other items, carried by creatures,
    who exist within rooms. Implementing
    the Visitor pattern for WorldEntities
    might work well.
  • CreatureType and ItemType classes
    which contain the 'class' data for
    individual Creature and Item
    instances, which refer back to their
    corresponding 'type' object. (eg. base
    hitpoints and stats in the former,
    current hitpoints and transient effects
    in the latter). I might implement these as
    prototypical lists of properties that get
    copied to Creature or Item instances when
    they are created. You can implement property
    inheritance via a 'parent' property so that
    a specific goblin Creature instance may relate to the
    'warrior goblin' CreatureType, which contains a
    parent reference to the 'generic goblin' CreatureType. And so on.
  • Exits that are owned by their Room, and are
    one way, and which detail the direction of
    travel, various conditions of passage, etc.
  • Areas, that contain groups of rooms connected
    by some logical organisation.
  • A Spawn class to dictate where Creature
    and Item instances are created (eg. which room,
    or at what coordinates), when they are created and
    with what frequency, and from
    which CreatureTypes and ItemTypes. You may have
    some logic in here to randomise things a bit.
  • Spells, skills, abilities, etc.
    all derived from a base Action class
    or interface that specifies prerequisites
    (eg. current position, mana points, some
    degree of learning of a skill, etc). Normal
    commands and actions can go here too since they
    often have some sort of requirements too
    (eg. a 'sleep' command requires that you're not
    already sleeping.)
  • A FutureEvent class which is essentially a
    callback that you push onto a priority queue
    to execute in the future. You can use these to
    schedule combat rounds, spell cool-down times,
    night/day cycles, whatever you like.
  • A hash/map/dictionary of name->value pairs for
    player and item statistics. Not type-safe but
    you'll appreciate the flexibility later. In my
    experience making stats member variables is
    workable but inflexible, and having specialise
    'attribute' classes becomes a convoluted
    nightmare when debugging.
  • A Modifier type which contains a stat name
    and a modifier value (eg. +10, +15%). These
    get added to your creatures as they are used
    (eg. through a spell effect, or by wielding
    an enchanted weapon) and get stripped off later
    by a timed FutureEvent or some other event such
    as a command being executed.
  • Game-specific classes such as PlayerClass or
    PlayerRace, each of which describe a player's class
    (eg. warrior, wizard, thief) or race (human, elf,
    dwarf) and set starting stat values and limits,
    skill availability lists, special powers, etc.
  • Basic player interface classes which will vary
    depending on your actual game type. You might
    have a rendering classes for a graphical game, or
    in a MUD you might have a Connection class
    reflecting the TCP connection to the player's client.
    Try to keep all game logic out of these.
  • A scripting interface. Most of your commands, spells,
    and creature AI can be realised more quickly with
    a decent scripting interface and it keeps compile times
    down too. It also allows for some great in-game debugging
    and diagnostic capabilities.

That would be the basic high level structure I'd use.

为你拒绝所有暧昧 2024-08-05 11:28:44

您可能需要考虑组件实体系统而不是传统的继承层次结构; 它们往往对某些类型的更改更加灵活,使工具(例如世界编辑器)开发更加容易,并提供并行化的机会,否则这些并行化可能并不明显或容易。

许多现代游戏引擎正在从“整体类对象”(或类实体,等等)转向“组件包”方法。

周围有许多书籍和文章。 一般来说:

特别是(一些值得注意的的,谷歌“组件”和“实体”的各种组合以获取更多信息):

每篇文章都链接到更多文章。

尝试一下 kool-aid,你可能会喜欢它。 =)

You may want to consider a component entity system rather than a traditional inheritance hierarchy; they tend to be more flexible to certain types of change, make tool (e.g. world editor) development much easier, and present opportunities for parallelization that might not otherwise be obvious or easy.

Many modern game engines are moving away from the "monolithic class Object" (or class Entity, whatever) and toward a "bag of components" approach.

There are numerous books and articles around. Generally:

Specifically (some noteworthy ones, google "component" and "entity" in various combinations for more):

Each of these articles links to a few more.

Try the kool-aid, you might like it. =)

对不⑦ 2024-08-05 11:28:44
<tongue_in_cheek_mode_because_it_is_friday>

刚开始:

          ----------------                    --------------
          |   Creature   |                    |  Item      |
          |--------------|                    |------------|
          | Name         |                    | Name       |
          | Hp           |                    | Value      |
          | Abilities    |--------------------| Weight     |
          |--------------|                    --------------
          | Attack       |
          ----------------
                 ^
                 |
        ----------------------
        |                    |
----------------    ----------------
|  Hero        |    |  Monster     |
|--------------|    |--------------|
| Level        |    |              |
|--------------|    |--------------|
| KillMonster  |    | AttackAndDie |
| GrabTreasure |    | DropTreasure |
----------------    ----------------

</tongue_in_cheek_mode_because_it_is_friday>
<tongue_in_cheek_mode_because_it_is_friday>

Just to start:

          ----------------                    --------------
          |   Creature   |                    |  Item      |
          |--------------|                    |------------|
          | Name         |                    | Name       |
          | Hp           |                    | Value      |
          | Abilities    |--------------------| Weight     |
          |--------------|                    --------------
          | Attack       |
          ----------------
                 ^
                 |
        ----------------------
        |                    |
----------------    ----------------
|  Hero        |    |  Monster     |
|--------------|    |--------------|
| Level        |    |              |
|--------------|    |--------------|
| KillMonster  |    | AttackAndDie |
| GrabTreasure |    | DropTreasure |
----------------    ----------------

</tongue_in_cheek_mode_because_it_is_friday>
冷情妓 2024-08-05 11:28:44

Steve Yegge 提出的非常不同的方法

A very different approach by Steve Yegge.

复古式 2024-08-05 11:28:44

请参阅 JADE 的 Javadoc 了解对复杂游戏的良好概述:)

Look at JADE's Javadoc for a good overview of a complex game :)

凉墨 2024-08-05 11:28:44

大胆一些,你的游戏不应该是砍伐式废话的克隆。
你的演员应该能够转换立场,采取主动
招募其他演员等等。否则,还有什么意义呢?

   +-----------------------------+
   V                             |
[Actor] ------- [Allegiance] ----+
 - risk comfort    - weight
 - temerity        

Be bold, your game shouldn't be a clone of hack and slash nonsense.
Your actors should be able to switch sides, take their own initiative
enlist other actors, etc. Otherwise, whats the point?

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