Snake
Snake

Reputation: 14678

Turn Base Match , how to update all devicesafter every turn

I was so excited to hear about the turn-based match in the new google game services but at the same time a bit disappointed to not see the "flow" of turn based game especially cards games will have hard time to fit the design into the "expected flow" by google turn base. One of the issues I found and I really hope that I missunderstood it in the documentation is updating the game state

According to the documentation, if a user takes a turn (lets say throw a an Ace of Heart) then this will information will be rendered only on the device of the next player. Is there no way to update this information on all the participants devices at the same time? Otherwise the 6th player will have to wait for 5 turns before seeing a movement on his screen!

Any idea?

Upvotes: 2

Views: 694

Answers (2)

user42754
user42754

Reputation: 26

I know this thread is old but anyway I'll put my two cents.

If you want be notified whenever any participant in the match takes a turn, attach a OnTurnBasedMatchUpdateReceivedListener to your activity. Whenever the match is updated following a player's turn, your listener is notified via the onTurnBasedMatchedReceived() callback.

You can attach a OnTurnBasedMatchUpdateReceivedListener like this.

    public class TurnBasedActivity extends BaseGameActivity implements OnTurnBasedMatchUpdateReceivedListener{ 

    @Override
    public void onSignInSucceeded() {
        Games.TurnBasedMultiplayer.registerMatchUpdateListener(getApiClient(), this);
    }   

    @Override
    public void onTurnBasedMatchReceived(TurnBasedMatch match) {
        Toast.makeText(this, "A match was updated.", TOAST_DELAY).show();
    }

    @Override
    public void onTurnBasedMatchRemoved(String matchId) {
        Toast.makeText(this, "A match was removed.", TOAST_DELAY).show();
    }
  }
}

I took the information from here https://developers.google.com/games/services/android/turnbasedMultiplayer#taking_the_first_turn

Hope it helps somebody else.

Upvotes: 1

ianhanniballake
ianhanniballake

Reputation: 200120

From the Saving Game State guide:

  1. Call takeTurn() and pass in your game state data as the matchData parameter.
  2. If the call is successful, Play Games services notifies other participants in the match about the update and makes the match data available on all participant devices.
  3. Your game can then call getData() to retrieve the updated game state.

So it appears all participants get the updated state.

Upvotes: 2

Related Questions