Gamecenter 对接会 - 如何区分玩家 1 和 2?

发布于 2024-12-17 02:00:08 字数 91 浏览 4 评论 0原文

我开始使用游戏中心配对编写游戏。现在,两个玩家可以相互连接,但我无法弄清楚如何区分玩家 1 和 2。例如,我希望玩家 1 能够移动玩家 1,而玩家 2 能够移动玩家2.

I am beginning to write a game using gamecenter matchmaking. Right now, two players can connect to each other, but I am having trouble figuring out how to distinguish between player 1 and 2. For example, I want player 1 to be able to move player 1 and player 2 to be able to move player 2.

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

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

发布评论

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

评论(2

青朷 2024-12-24 02:00:08

该实现将特定于您的应用程序,因此很难更具体地回答,但基本上每个人的应用程序实例都可以有一个“本地玩家”对象和一个“对手”对象......它们两个可以在本地实例中移动“本地玩家”,并且对其“玩家”的更改显然会映射到另一端的“对手”。

The implementation would be specific to your app so it would be hard to answer more specifically, but basically each person's instance of the app could have an object that is "local player" and an object that is "opponent"... Both of them get to move the "local player" in their local instance, and changes to their "player" are obviously mapped to the "opponent" at the other end.

不气馁 2024-12-24 02:00:08

只需进行随机数交换来决定谁将成为玩家 1 并采取第一步。

生成一个随机数并将其存储在变量中。

将生成的随机数发送给对手。

就像这样,你的对手将他自己的随机数发送给你。

当你收到它时,与你的进行比较。

如果你的比他的大,那么你是player1,他是player2。所以你将迈出第一步。

如果你的比他的小,那么你是player2,他是player1。所以他会迈出第一步。

如果你的号码和他的号码相同(非常罕见的情况),请重复该过程。

提醒一下,您需要区分消息类型。因此使用不同的消息类型标头。例如:“R”表示随机,“M”表示移动。

Just do a random number exchance to decide who will be player1 and make the first move.

Generate a random number and store it in a variable.

Send that generated random number to opponent.

Just like this, your opponent sends his own random number to you.

When you receive it, compare with yours.

If yours is greater than his, then you are player1 and he is player2. So you will make the first move.

If yours is lesser than his, then you are player2 and he is player1. So he will make the first move.

If yours and his number are equal (a very rare case) repeat the procedure.

As a reminder, you need to distinguish message types. So use different message type headers. For example: 'R' for random, 'M' for moves.

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