在我的回合制比赛中,当一名失控球员退出比赛时,我无法干净地结束比赛。我相信这阻止了我开始复赛。
这是我观察到的。当我从玩家1的设备的GKTurnBasedMatchmakerViewController检查该游戏的完成游戏状态时,它显示玩家1的匹配结果是退出并且玩家2的匹配结果是"该玩家'转过来#34;但是,如果我从播放器2的设备的GKTurnBasedMatchmakerViewController检查此游戏的完成游戏状态,则表明玩家1的匹配结果是退出,而玩家2的匹配结果是"赢了&#34 ;。但是,如果我点击"查看游戏"从播放器1设备内的GKTurnBasedMatchmakerViewController,匹配结果切换到"赢得"对于玩家2.如何正确结束此游戏,以便玩家2的匹配结果为"赢得"从玩家1的角度来看?
在我的场景中,玩家1开始一场比赛并轮到他。然后玩家2开始转弯。在此期间,玩家1退出比赛。代码序列如下:
玩家1:
[currentMatch participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:nil];
播放器2 - 收到对handleTurnEventForMatch的调用后:didBecomeActive:
// For each participant, set their matchOutcome relative to the local player who has just won.
for (GKTurnBasedParticipant *part in [currentMatch.participants) {
if ([part.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]) {
part.matchOutcome = GKTurnBasedMatchOutcomeWon;
}
else {
part.matchOutcome = GKTurnBasedMatchOutcomeQuit;
}
}
[currentMatch endMatchInTurnWithMatchData: data
completionHandler: ^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
else {
NSLog(@"After win: match ended successfully");
}];
玩家1会收到提示,询问他们是否需要重赛。如果用户肯定地回答,则发送以下内容:
[currentMatch rematchWithCompletionHandler:^(GKTurnBasedMatch *reMatch, NSError *error) {
if (error) {
NSLog(@"In rematchWithCompletionHandler. Error creating rematch: %@", error.localizedDescription);
} else {
NSLog(@"Success");
}];
不幸的是,由于播放器2的状态不正确,上述重新匹配尝试失败。上面的结果错误消息是:
The requested operation could not be completed because the match request is invalid.
以下堆栈溢出问题表明这是由于上述错误匹配数据:Trouble Using the new rematchWithCompletionHandler method from Game Center
答案 0 :(得分:0)
为了解决这个问题,我不得不以编程方式加载匹配数据,以强制播放器2的matchOutcome切换到" Won"的状态。因此,当用户确认重新匹配的提示时,我不会立即调用rematchWithCompletionHandler,而是在确认重新匹配的提示时执行以下操作:
[GKTurnBasedMatch loadMatchWithID:currentMatch.matchID withCompletionHandler:
^(GKTurnBasedMatch *match, NSError *error) {
if (error) {
NSLog(@"In requestRematch, failed to receive match data: %@", error.localizedDescription);
}
else {
// Received the match data. Now request a rematch
[match rematchWithCompletionHandler:
^(GKTurnBasedMatch *reMatch, NSError *error) {
if (error) {
NSLog(@"In requestRematch: rematchWithCompletionHandler. Error creating rematch: %@", error.localizedDescription);
}
else
{
NSLog(@"In requestRematch: Rematch granted with new matchID=%@. currentMatch was: %@", match.matchID, currentMatch.matchID);
// Do something with the reMatch data
}
}];
}
}];