//Determine who the next active player is, and return the associated state. BalloonPopGameStates DetermineNextActivePlayer(int currentPlayerPosition) { //Create the return value. Assigns a value to prevent compiler errors. BalloonPopGameStates nextActivePlayer = BalloonPopGameStates.PlayerTurn; //To handle looping around, we'll use a bool to determine if we need to loop around at all. bool hasDeterminedNextPlayer = false; //Create the int to hold the next player's position. int nextPlayerPosition = 0; //If this is the last player, there's no one ahead to look at. if (currentPlayerPosition != 3) { //Check if the players ahead of the current player are active. for (int i = currentPlayerPosition + 1; i < 4; i++) { if (activePlayers[i] == true) { //This player is active. Set the player position, set the determination bool to true, and break out of the loop. nextPlayerPosition = i; hasDeterminedNextPlayer = true; break; } } } //Next, handle the players behind the current player, if none ahead were active. if (!hasDeterminedNextPlayer) { for (int i = 0; i < currentPlayerPosition; i++) { if (activePlayers[i] == true) { //This player is active. Set the player position, and break out of the loop. nextPlayerPosition = i; break; } } } //By this point, we know the next active player by the position we have. switch (nextPlayerPosition) { case 0: nextActivePlayer = BalloonPopGameStates.PlayerTurn; Debug.Log("Player turn."); break; case 1: nextActivePlayer = BalloonPopGameStates.AI1Turn; Debug.Log("AI 1 turn."); break; case 2: nextActivePlayer = BalloonPopGameStates.AI2Turn; Debug.Log("AI 2 turn."); break; case 3: nextActivePlayer = BalloonPopGameStates.AI3Turn; Debug.Log("AI 3 turn."); break; default: Debug.Log("DetermineNextActivePlayer returned a non-existent player."); break; } //Return the proper game state. return(nextActivePlayer); }