假设我有一个有两个玩家的GKTurnBasedMatch,第二个玩家在轮到他的时候被罚了。我该如何向第一个知道游戏已经结束的用户显示呢?或者让第一个玩家以编程方式退出?
另一个GKTurnBasedMatch-这次,12个玩家。我不明白这里的一件事--比方说玩家7退出了,这意味着当轮到他时,游戏就会卡住,我需要以编程的方式结束对所有用户的比赛?或者GC会相应地对剩下的玩家进行重新编号?
提前感谢!
发布于 2013-02-18 16:58:21
您需要将以下内容之一发送到GKTurnBasedMatch对象:
- (void)participantQuitInTurnWithOutcome:(GKTurnBasedMatchOutcome)matchOutcome
nextParticipants:(NSArray *)nextParticipants
turnTimeout:(NSTimeInterval)timeout
matchData:(NSData *)matchData
completionHandler:(void (^)(NSError *error))completionHandler
- (void)participantQuitOutOfTurnWithOutcome:(GKTurnBasedMatchOutcome)matchOutcome
withCompletionHandler:(void (^)(NSError *error))completionHandler调用participantQuitOutOfTurnWithOutcome会向比赛中的其他玩家发送一个turn事件,通知他们有玩家退出了。玩家在match.participants中的对象将具有matchOutcome GKTurnBasedMatchOutcomeQuit
发布于 2017-07-28 06:12:49
我已经创建了一个game kit turn based match example project,它演示了轮流退出和轮流退出。看看GameModel.swift文件中的quit()函数,看看如何调用这些函数:
func quit(completionHandler: @escaping (Error?) -> Void) {
if isLocalPlayerTurn {
let next = nextParticipants()
let data = NSKeyedArchiver.archivedData(withRootObject: self)
match?.participantQuitInTurn(with: .quit, nextParticipants: next, turnTimeout: 600, match: data) { error in
completionHandler(error)
}
} else {
match?.participantQuitOutOfTurn(with: .quit) { error in
completionHandler(error)
}
}
}当然,检查是否有人赢了也很重要。下面是同一文件中的checkForWin()函数。
func checkForWin(completionHandler: @escaping (Bool, Error?) -> Void) {
guard let stillPlaying = match?.participants?.filter({ $0.matchOutcome == .none }),
stillPlaying.count == 1,
stillPlaying[0].player?.playerID == currentPlayerID
else {
return completionHandler(false, nil)
}
stillPlaying[0].matchOutcome = .won
let data = NSKeyedArchiver.archivedData(withRootObject: self)
match?.endMatchInTurn(withMatch: data) { error in
print("***** match ended")
completionHandler(true, error)
}
}在整个示例项目的上下文中,所有这些都更有意义。我希望它能帮上忙。
https://stackoverflow.com/questions/11920775
复制相似问题