类图问题(UML)

发布于 2024-10-07 02:28:50 字数 105 浏览 0 评论 0原文

好的,所以我想制作一个游戏,但在对类图进行排序时遇到一些困难。

这适用于以下用例: 用户装备武器。 (用户只能选择解锁的武器,) 例如,如果有两种武器,其类图会是什么样子?提前致谢

ok so I want to make a game but am having some difficulty in getting the class diagram sorted.

this would be for the Use case of :
user Equips weapon. (user can select unlocked weapons only,)
what would the class diagram of this look like with 2 weapons for instance ? thanks in advance

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

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

发布评论

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

评论(2

笑饮青盏花 2024-10-14 02:28:50

下面是一个示例 UML 图,对您在问题中描述的关系进行建模。请注意,该图假设玩家始终拥有至少一件解锁的武器,并且玩家始终拥有一件且仅有一件选定的武器。

替代文字

Here is an example UML diagram modeling the relationships you describe in your question. Note that this diagram assumes that the player always has at least one weapon unlocked and that the player always has one and only one selected weapon.

alt text

摇划花蜜的午后 2024-10-14 02:28:50

呃,什么?你能问更具体的问题吗?

或者至少提供你已经拥有的东西?

您可能已经有了玩家和武器类别,对吧?

类玩家(您命名的用户)与名为unlockedWeapons 的武器与类武器具有多重性* 的单向关联。与名为 currentWeapon 的类武器的另一个关联,重数为 1,也是单向的。

然后,玩家类会获取一些方法,例如 equip(Weapon Weapon) ,它获取武器对象,检查有效性(是否已解锁)等。

是否有 2 种武器都无关紧要。如果您指的是 2 种不同类型的武器,它们是继承 Weapon 类的子类,则玩家可能仍然会与 Weapons 关联以进行抽象。

为此设计类图确实是 UML 建模/软件设计中最基本的事情。

Eh, what? Could you ask more specific questions?

Or at least provide what you already have?

You probably do already have player and weapon classes, right?

Class player (what you named user) with a one-way association with multiplicity * to weapons named unlockedWeapons to the class weapon. Another association to the class weapon named currentWeapon with multiplicity 1, also one-way.

Class player then gets some methods, like equip(Weapon weapon) which gets a Weapon object, checks for validity (is it unlocked) etc.

Whether it’s 2 weapons or not is irrelevant. If you mean 2 different types of weapons, which are subclasses inheriting the Weapon class, the player probably still associates with Weapons for abstraction.

Designing a class diagram for that is really the most basic thing to do in UML modeling / software design.

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