我很难找到有关此的任何信息,并且我遇到的所有代码示例都是基于所有玩家都以平局结束的比赛。在我的 2 人回合制游戏中,我希望能够以赢家和输家结束比赛。使用下面的代码,我编写的比赛总是以两个玩家的相同结果结束,如果赢了,那么玩家 1 和 2 都赢了,如果输了,玩家 1 和 2 都松了……有什么帮助吗?谢谢你。
if (gameOver == true) {
if (GameWinner == 0) {
GKTurnBasedParticipant *player0 = [currentMatch.participants objectAtIndex:0];
player0.matchOutcome = GKTurnBasedMatchOutcomeWon;
GKTurnBasedParticipant *player1 = [currentMatch.participants objectAtIndex:1];
player1.matchOutcome = GKTurnBasedMatchOutcomeLost;
[currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
}];
testlabel.text = @"Player 1 Wins!";
} else if (GameWinner == 1) {
GKTurnBasedParticipant *player0 = [currentMatch.participants objectAtIndex:0];
player0.matchOutcome = GKTurnBasedMatchOutcomeLost;
GKTurnBasedParticipant *player1 = [currentMatch.participants objectAtIndex:1];
player1.matchOutcome = GKTurnBasedMatchOutcomeWon;
[currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
}];
testlabel.text = @"Player 2 Wins!";
} else if (GameWinner == 2) {
for (GKTurnBasedParticipant *part in currentMatch.participants) {
part.matchOutcome = GKTurnBasedMatchOutcomeTied;
}
[currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
}];
testlabel.text = @"Tie Game!";
} else {
testlabel.text = @"Your turn is over.";
}