I’m doing a turn based game... the only information transferred is the score of the player and whether a turn has been sent.
When the next player receives the turn. The data gets stored into “scoreToBeat” and turnSent=1. The player then takes their turn. Afterward the game ended gets called because turnSent=1. I used the turn based tutorial by Ray Wenderlich at http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1.
In his case the game ends and is a tie. Like this... I can’t seem to get it to show the person that lost.
for (GKTurnBasedParticipant *part in currentMatch.participants) {
part.matchOutcome = GKTurnBasedMatchOutcomeTied;
}
I can’t seem to get it to show the person that lost it always shows a win. This is my latest attempt of many... Exactly 2 players in the match btw... Any ideas would be greatly appreciated.
for (GKTurnBasedParticipant *part in currentMatch.participants) {
if(part==currentMatch.currentParticipant)
{
if(points>scoreToBeat)
{
part.matchOutcome=GKTurnBasedMatchOutcomeWon;
}
else {
part.matchOutcome=GKTurnBasedMatchOutcomeLost;
}
}
else {
if(points>scoreToBeat)
{
part.matchOutcome=GKTurnBasedMatchOutcomeLost;
}
else {
part.matchOutcome=GKTurnBasedMatchOutcomeWon;
}
}
This is an excerpt from my latest project, good for a 2 player game. It's called during the sendTurn process, when the game is decided to be ending. This is more correct than the previous answer (first code block), in my opinion, because you must set the matchOutcome for all participants before ending the game.
If you had more than 2 players, then you'd have to loop through all participants and set the matchOutcome accordingly.
Note that you will see "Won" on both devices by design.
One will say "Me" with "Won" underneath, and the other will say "(Winners Name)" with "Won" underneath.
points is the local points scored on the device right? if so, I would do the following:
Also, remember to use a NSLog to see if score to beat is actually transferred. One mistake you can do to keep on using currentTurnBasedMatch.matchData, you should set the currentTurnBasedMatch to GKTurnBasedMatch that is returned in delegate methods.
EDIT: A code snipped I use looks like this