Reputation: 6709
When you click Play! on my chess app, it takes you to the select players screen like so...
NOTE: mGamesClient is a GameClient
that has been connected using mGamesClient.connect()
.
Intent intent = mGamesClient.getSelectPlayersIntent(1, 1, true);
startActivityForResult(intent, RC_SELECT_PLAYERS);
Now after I select my player (only one player because it's chess) I get the onActivityResult
callback, which looks like this...
@Override
public void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
if (request == RC_SELECT_PLAYERS) {
if (response != Activity.RESULT_OK) {
// user canceled
return;
}
// get the invitee list
final ArrayList<String> invitees = data
.getStringArrayListExtra(GamesClient.EXTRA_PLAYERS);
// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers = data.getIntExtra(
GamesClient.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers = data.getIntExtra(
GamesClient.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
if (minAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} else {
autoMatchCriteria = null;
}
TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
.addInvitedPlayers(invitees)
.setAutoMatchCriteria(autoMatchCriteria).build();
// kick the match off
mGamesClient.createTurnBasedMatch(this, tbmc);
}
Log.v("LOG", "+++ ONACTIVITYRESULT HOMESCREENACTIVITY +++");
}
Now because mGamesClient.createTurnBasedMatch(this, tbmc);
gets called, I get a onTurnBasedMatchInitiated
callback, which looks like this...
@Override
public void onTurnBasedMatchInitiated(int statusCode, TurnBasedMatch match) {
Log.v("LOG", "+++ ONTURNBASEDMATCHINITIATED HOMESCREENACTIVITY +++");
mMatch = match;
// Check if the status code is not success;
if (statusCode != GamesClient.STATUS_OK) {
showErrorMessage(statusCode);
Log.v("LOG", "" + statusCode);
return;
}
Intent i = new Intent(getApplicationContext(), OfflineInGameActivity.class);
i.putExtra("soundOn", soundOn);
i.putExtra("LoLImages", LoLImages);
startActivity(i);
return;
}
And now my chess activity starts. On my opponents side, he/she recieves an invitation which, if accepted, will call acceptTurnBasedInvitation
.
Now my problem is, neither of the players can make a move, for each player it says its not their turn.
Upvotes: 0
Views: 251
Reputation: 3489
This should help:
Deciding who is player one and two in a round based game with Google Play Game Services
Here is the relevant section from the google documentation :
https://developers.google.com/games/services/android/turnbasedMultiplayer#taking_the_first_turn
Upvotes: 1