Gamecenter 对接会 - 如何区分玩家 1 和 2?
我开始使用游戏中心配对编写游戏。现在,两个玩家可以相互连接,但我无法弄清楚如何区分玩家 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该实现将特定于您的应用程序,因此很难更具体地回答,但基本上每个人的应用程序实例都可以有一个“本地玩家”对象和一个“对手”对象......它们两个可以在本地实例中移动“本地玩家”,并且对其“玩家”的更改显然会映射到另一端的“对手”。
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.
只需进行随机数交换来决定谁将成为玩家 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.