Search code examples
androidgoogle-playgoogle-play-servicesgoogle-play-games

End a multiplayer game on finishMatch


I am developing a turn based multiplayer game in Android using Google Play Game Services.

I have successfully ended the game when the user clicks the Finish Button:

    Games.TurnBasedMultiplayer.finishMatch(mGoogleApiClient, mMatch.getMatchId(), mMatch.getData(), creatorResult, opponentResult)
            .setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
                @Override
                public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
                    processResult(result);
                }
            });

The current player's game gets updated in the "Completed Games" section.

However the opponent's game is listed as "My Turn"

From the Developing a Turn Based Multiplayer Game in Android page:

"Play Game services sends a notification to all other match participants to inform them that the match is over. These participants see this match under Your Turn category in their respective match list UIs. At this point, your game can call finishMatch() for these participants to save their final game data. Invoking this method also moves the match to the Completed Matches category in the participant’s match list UI."

How do I call finishMatch for the other players?

--Is it through the mGoogleApiClient

--Or is there a way to make the oppononent's match status = MATCH_STATUS_COMPLETE

Can someone please help?


Solution

  • You should make the following call on each of the other players devices:

    Games.TurnBasedMultiplayer.finishMatch( mGoogleApiClient, mMatch.getMatchId());
    

    This will cause the following status changes on each players device:

    • Match status will change from MATCH_STATUS_ACTIVE to MATCH_STATUS_COMPLETE
    • Match turn Status will change from MATCH_TURN_STATUS_MY_TURN to MATCH_TURN_STATUS_COMPLETE.
    • The participant status of the player will change from STATUS_JOINED to STATUS_FINISHED.

    Note that a players participant status may remain STATUS_JOINED on the other players devices (at least thats what I see in my implementation).