2012-04-26 90 views
1

我背後有我的辭職按鈕下面的代碼:辭職在回合制遊戲(遊戲中心)

currentMatch.currentParticipant.matchOutcome = GKTurnBasedMatchOutcomeWon; 
nextParticipant.matchOutcome = GKTurnBasedMatchOutcomeLost; 
[currentMatch participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeLost 
           nextParticipant:nextParticipant matchData:data 
          completionHandler:^(NSError *error) { 
                if (error) { 
                 NSLog(@"%@", error); 
                } 
                else { 
                 [statusLabel setString:@"You resigned"]; 
                }]; 

它說:「你辭職」,但對方沒有給出通知,又是剛傳給他。對手現在不能做任何動作,否則會造成錯誤。完成比賽的唯一方法是讓對手也辭職。

任何人都可以看到上述代碼有什麼問題嗎?

回答

2

上面的代碼沒有錯。遊戲中心基於回合的作品是下一個玩家需要處理他的回合,並決定遊戲是否結束,並退出或繼續遊戲(如果玩家超過2個,則更有意義)。所以這是你的遊戲代碼的一部分。

只要您不再將離開的播放器設置爲下一個參與者,就應該可以繼續播放。你做不到。 (如果你想繼續遊戲,你應該把結果設置爲GKTurnBasedMatchOutcomeQuit而不是丟失)

如果你真的想在那一刻結束所有玩家的遊戲,你可以設置該比賽參與者的所有結果爲你認爲合適的,然後用

[currentMatch endMatchInTurnWithMatchData:data completionHandler:(void (^)(NSError *error))completionHandler]; 

結束比賽的所有玩家。