我正在研究基于回合的GameCenter游戏。使用GKTurnBasedMatch创建GKMatchRequest,并将minPlayersmaxPlayers设置为2。在尝试以NSInvalidArgumentException结束游戏时,我得到了endMatchInTurnWithMatchData,这告诉我我并未在所有参与者上都设置matchOutcome。在此之前的比赛对象日志显示,我的比赛如下所示:

<GKTurnBasedMatch 0x1c1f2af0 - matchID:c9de6e47-0e9a-4dbe-944b-d2fd4ecd3044 bundleID:com.mybundle.wd status:GKTurnBasedMatchStatusEnded message:'Game Over' creationDate:2013-10-08 01:26:12 +0000 currentParticipant:(null) participants:
<GKTurnBasedParticipant 0x1c184820 - playerID:G:128458444 (local player) status:Done matchOutcome:Lost lastTurnDate:2013-10-10 21:54:22 +0000 timeoutDate:(null)>,
<GKTurnBasedParticipant 0x1c1b0a80 - playerID:G:220673962 status:Done matchOutcome:Lost lastTurnDate:2013-10-10 18:26:16 +0000 timeoutDate:(null)>,
<GKTurnBasedParticipant 0x16ef1610 - playerID:G:128458444 (local player) status:Active matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>,
<GKTurnBasedParticipant 0x16ec64f0 - playerID:(null) status:Matching matchOutcome:None lastTurnDate:(null) timeoutDate:(null)> matchData.length:871 matchDataMaximumSize:65536 exchanges:(null)>

我在这里有2个以上的GKTurnBasedParticipants,其中两个是同一位玩家!除了在每个回合中打以下电话外,我在游戏中没有做任何非凡的事情:
[match endTurnWithNextParticipants:@[nextParticipant] turnTimeout:GKTurnTimeoutDefault matchData:data completionHandler:^(NSError *error){...}]

有人知道这是怎么回事吗?这是一个两人游戏,所以我如何最终弄得乱七八糟的比赛对象,又该如何防止呢?

最佳答案

我执行以下操作以结束游戏

        ((GKTurnBasedParticipant*)[currentMatch.participants objectAtIndex:1]).matchOutcome = GKTurnBasedMatchOutcomeWon;
        ((GKTurnBasedParticipant*)[currentMatch.participants objectAtIndex:0]).matchOutcome = GKTurnBasedMatchOutcomeLost;

然后我打电话
[currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error)
{
         if (error)
         {
             NSLog(@"%@", error);
         }
         else{


         }
     }];

关于objective-c - GKTurnBasedMatch参与者不正确/重复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19307171/

10-09 02:28