Game Center Finding a Match Programmatically

后端 未结 3 948
青春惊慌失措
青春惊慌失措 2021-02-13 16:00

I just can\'t figure out how this works. What I am trying to do is let two players play a game if a third player joins it can instantly join the game, if the fourth and last pla

3条回答
  •  温柔的废话
    2021-02-13 16:31

    Which device should actually call the addPlayersToMatch method? And how can you restrict it to one device executing that method?

    You could solve this problem by having the devices "draw straws". Each device generates a random number, then sends it to the others. The device with the largest number is the leader, and it is the one that must call addPlayersToMatch. If two devices pick the same number, throw out the numbers and start over.

提交回复
热议问题