I’m trying to finding out who the next player is in a turn based poker game. In objective c there’s no problem, but since Im new to php, I’m not quite sure how to write this loop:
for (int i = 0; i < [match.participants count]; i++)
{
nextParticipant = [participantsArray objectAtIndex:((currentIndex + 1 + i) % [match.participants count])];
if (nextParticipant.matchOutcome != GKTurnBasedMatchOutcomeQuit)
{
//NSLog(@"isn't quit %@", nextParticipant);
nextPlayer = nextParticipant;
break;
}
else
{
//NSLog(@"Player not active, continue the for loop to get the next player");
}
}
So the loop loop through all the participant in the array. THe currentIndex is the index the previous player was at.
So after each turn, the player send his information to the server, along with his index. So if player 4 made his turn, the script should send the turn to player 5, but only if he’s active (his status is set to 4, see below)
I can get the active players from the server by:
$query = "SELECT player1Status, player2Status, player3Status, player4Status,player5Status,player6Status WHERE match_id='$match_id'";
while ($row = mysql_fetch_object($result)) {
$player1Status = $row['player1Status'];
$player2Status = $row['player2Status'];
$player3Status = $row['player3Status'];
$player4Status = $row['player4Status'];
$player5Status = $row['player5Status'];
$player6Status = $row['player6Status'];
}
And I also have the information about the match:
$numberOfPlayersInMatch
$currentPlayerIndex
I just don’t know how to put it all together in a good way. Any help is very appreciated. Thanks
Note: This is not tested.
You can change instead of putting the player status in $player1Status, $player2Status, put it in an array like
$nextPlayerIndex value ranges : 0 – 5