菜鸟教程小白 发表于 2022-12-12 23:52:09

iphone - 如何为 GameCenter 设置自定义规则(例如难度级别)以找到匹配项


                                            <p><p>需要动态设置一些游戏规则,并在玩家连接之前通知可能的玩家(在 GC 搜索玩家/自动机时)这些规则。假设我想主持/开始游戏,我想设置一些投注单位的起始数量(10...1000)、难度级别(0...10)、评分系统(0..3)等。我想这就像一个表格,其中包含提供此信息的单元格,因此玩家可以决定他/她是否想加入并按照这些规则玩游戏。如何实现?<br/>
AFAIK GKMatch 在搜索玩家时仅使用最小和最大数量的玩家,仅此而已。我可以在邀请中提供此类信息,但我需要其他玩家自己寻找游戏,例如浏览现有游戏,包括规则。自游戏开始以来,我的游戏不允许加入玩家,但我需要以某种方式填补 session 所需的玩家数量。就像我只想和一个玩家一起玩一样,我开始游戏时玩家数量=2(以及一些自定义规则),所以我需要 GC 来帮助我找到对面的玩家。在加入我之前,该玩家应该被告知我的规则。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你有两种可能:</p>

<p>使用 <code>GKMatchRequest</code> 的这些属性:</p>

<blockquote>
<p><code>@property(nonatomic, assign) uint32_t playerAttributes</code></p>

<p><em>A mask that specifies the role that the local player would like to
play in the game.</em></p>

<p>If this value is 0 (the default), this property is ignored.
If the value is nonzero, then automatching uses the value as a mask
that restricts the role the player can play in the group. Automatching
with player attributes follows two rules:</p>

<p>A new player can only be added to the match if the bitwise AND of that
player’s mask and the mask of any player already in the match equals
0x00000000. Players are added to the match until the bitwise OR of the
masks of all the players in the match equals 0xFFFFFFFF. For more
information, see Game Kit Programming Guide.</p>

<p><code>@property(nonatomic, assign) NSUInteger playerGroup</code></p>

<p><em>A number identifying a subset of players
allowed to join the match.</em></p>

<p>If your game sets the playerGroup property, only players whose
requests share the same playerGroup value are automatched by Game
Center. You can use any values you want for player groups. For
example, you could define different playerGroup values to implement
any of the following filters:</p>

<p>A game could restrict players based on skill level. A game that
provides multiple games could use it to filter players into the
specific game they want to play. A game with multiple victory
conditions (for example, Capture-The-Flag, Survival) could match
players to others interested in the same rules. A game that provides
bonus content through in-app purchase could match players who own the
same content with each other.</p>
</blockquote>

<p>这允许在搜索玩家之前进行一些游戏配置。</p>

<p>对于复杂的规则,您需要在找到比赛并连 catch 员后发送配置数据(请参阅 GKMatch API)。这里需要使用可靠传输模式。</p>

<p>你也可以结合这两个想法。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何为 GameCenter 设置自定义规则(例如难度级别)以找到匹配项,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/13588628/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/13588628/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何为 GameCenter 设置自定义规则(例如难度级别)以找到匹配项