如何管理数据的微小变化?

发布于 2024-08-16 23:26:42 字数 339 浏览 6 评论 0原文

我目前正在构建一个多人游戏系统,我有一个设计问题,关于如何管理大量对象之间数据的大量微小变化。

我将从一个例子开始:假设我有 3 个玩家:A、B 和 C。 A 与 B 是友好的,与 C 是敌人。这意味着,我必须向 C 表明 A 是敌人,而 B 表明 A 是友好的。 现在我有相同数据的 2 个不同(但很小)的变体。这只是一个例子。另一种变化是 A 进入隐身状态,B 可以看到 A,但 C 将看不到 A。 如前所述,这些只是示例。计划拥有更多和不同状态的玩家数据,每个对象之间的数据大多不同。

我应该如何处理这个问题?大量的 if 块,或者我是否错过了一些明显的设计模式?由于这是一款多人游戏,因此将不仅仅是 3 个玩家/对象或状态。

I am currently building a multiplayer system, and I have a design question about how to manage lot small variations of data between lot of objects.

I'll start with an example: Let's say I have 3 players: A, B and C.
A is friendly with B and enemies with C. That means, I must show C that A is an enemy and B that A is friendly.
Now I have 2 different (but small) variations of the same data. This is just an example. Another variation would be that A goes into stealth, and B can see A, but C would not be able to see A.
As said, these are just examples. It is planned to have much more and different states of player data, mostly varying between each object.

How should I manage this? A ton of if blocks, or is there some obvious design pattern I have missed? Since this is a multiplayer game, there will be much more than just 3 players/objects or states for that matter.

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

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

发布评论

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

评论(3

不弃不离 2024-08-23 23:26:42

如果您对面向对象编程的概念感到困惑,那么最好的办法就是尝试牢牢掌握面向对象编程的概念。您似乎没有一个关于需要存储哪些状态数据的清晰模型。尝试绘制游戏的“状态”图表;将其视为给定时间游戏中存在哪些对象以及它们如何组织的最小快照。像player.canSee(otherPlayer)这样的东西可以被计算,并且不一定需要存储。

即使您可能根本不会使用数据库,您可能会发现阅读和练习关系数据库设计很有帮助。关系设计的概念将帮助您以清晰、一致的方式组织您的想法并存储信息。

The best thing to do is try to get a solid grasp on object-oriented programming, if you're struggling with the concept. It seems like you don't have a clear model of what state data you will need to store. Try diagramming the "state" of your game; think of it as a minimal snapshot of what objects exist in your game at a given time, and how they are organized. Something like player.canSee(otherPlayer) can be calculated, and doesn't necessarily need to be stored.

Even though you probably will not use a database at all, you might find it helpful doing some reading and practice with relational database design. The concepts of relational design will help you organize your thoughts and store information in a clear, consistent way.

许你一世情深 2024-08-23 23:26:42

好吧,一个玩家的类,其中有一个朋友列表和一个敌人列表。

这要么是一个非常简单的问题,要么是一个非常复杂的问题;如果真的很复杂,那么你给我们的还不够继续。

Well, a class for a player, and in it a list of friends, and a list of enemies.

This is either a really simple question or a really complex one; if really complex, you haven't given us nearly enough to go on.

无需解释 2024-08-23 23:26:42

你的问题在于将国家视为人们所看到的所有排列。一般来说,你应该只将状态视为情况的事实,并根据需要计算这些事实的个人观点。

// pseudocode - make it properly object oriented for best results
struct player
{
    int teamNumber;
    bool hidden;
};

bool is_friend(player other_guy)
{
    return me.teamNumber == other_guy.teamNumber;
}

bool can_see(player other_guy)
{
    return (is_friend(other_guy) || !other_guy.hidden);
}

如果一个玩家(例如,A)看不到另一位玩家(例如,B),那么您只需在情况发生变化之前就不会将玩家 B 的信息发送给玩家 A。

Your problem is thinking of the state as being all the permutations of what people can see. In general you should just be thinking of the state as the facts of the situation, and calculate individual views of those facts as they are needed.

// pseudocode - make it properly object oriented for best results
struct player
{
    int teamNumber;
    bool hidden;
};

bool is_friend(player other_guy)
{
    return me.teamNumber == other_guy.teamNumber;
}

bool can_see(player other_guy)
{
    return (is_friend(other_guy) || !other_guy.hidden);
}

If one player (eg, A) cannot see another player (eg. B), then you just don't send player B's information to player A until the situation changes.

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