我正在开发一个基于游戏中心的 2 人游戏。游戏玩法是;
1) 玩家 1 发起挑战。
2) 玩家 1 轮到他/她。(回答游戏提出的 5 个问题)
3)玩家 1 发送存储在数组中的 5 个问题以及他/她的分数信息。
4) 玩家 2 收到挑战并接受它。
5) 玩家 2 回答相同的问题并显示两个玩家的结果。
6) 玩家 1 被告知玩家 2 的结果。
7) 比赛结束。
我使用以下代码;
- (IBAction)sendTurn:(id)sender {
GKTurnBasedMatch *currentMatch = [[GCTurnBasedMatchHelper sharedInstance] currentMatch];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:challengedQuestions]; //sends same same questions answered by player1 to player 2 in an array
NSUInteger currentIndex = [currentMatch.participants indexOfObject:currentMatch.currentParticipant];
GKTurnBasedParticipant *nextParticipant;
NSUInteger nextIndex = (currentIndex + 1) % [currentMatch.participants count];
nextParticipant = [currentMatch.participants objectAtIndex:nextIndex];
for (int i = 0; i < [currentMatch.participants count]; i++) {
nextParticipant = [currentMatch.participants objectAtIndex:((currentIndex + 1 + i) % [currentMatch.participants count ])];
if (nextParticipant.matchOutcome != GKTurnBasedMatchOutcomeQuit) {
NSLog(@"isnt' quit %@", nextParticipant);
break;
} else {
NSLog(@"nex part %@", nextParticipant);
}
}
if (turnCounter > 0)
{
for (GKTurnBasedParticipant *part in currentMatch.participants) {
part.matchOutcome = GKTurnBasedMatchOutcomeTied;
}
[currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
}];
statusLabel.text = @"Game has ended";
LYResultsViewController *controller = [[LYResultsViewController alloc] init];
[controller setChallenge:self.challenge];
[self.navigationController pushViewController:controller animated:YES];
}
else {
[currentMatch endTurnWithNextParticipant:nextParticipant matchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
statusLabel.text = @"Oops, there was a problem. Try that again.";
}
else {
statusLabel.text = @"Your turn is over.";
LYResultsViewController *controller = [[LYResultsViewController alloc] init];
[controller setChallenge:self.challenge];
[self.navigationController pushViewController:controller animated:YES];
}
}];
}
NSLog(@"Send Turn, %@, %@", data, nextParticipant);
turnCounter++;
}
问题是如何将数组和玩家 1 的分数发送到同一个 NSData 变量中?
我如何通知玩家 1 玩家 2 的结果?
请帮忙