Search code examples
androidgoogle-play-servicesmultiplayergoogle-play-games

Real time Multiplayer or Turn based multiplayer API?


I am new to multi-player game development. I am basically making a board game for Android which requires to have a time limit for taking a turn, kind of like Online Multiplayer Chess which has a turn timer for both players. A timer runs when a player has to make a move and continues from where it left of when the same player needs to make a move. Similar timer is maintained for the second player.

I am not exactly getting which API should I use for this purpose. Real time Multiplayer or Turn based multi-player API? Any suggestions?

Update: I have finally used the Real Time Multiplayer(RTM) API as it provides almost everything. Basically it makes a room that checks for player drop-out unlike Turn Based API which is asynchronous and there is no direct way to check player drop-out in it. Plus RTM provides Real time sharing which I require due to my game complexity(I needed a way in which I can show every move that the other player makes before making a final move which will act as a turn changer).

Now the thing that was not provided was the turn mechanism which I implemented myself in the Real Time API. I have modified the Button Clicker and the results are as follows:

The other player is chosen as the first player

https://i.sstatic.net/VbBvt.png

Once the other player clicks on the button, the turn changes and also score updates to 1. (Score is modified to a no. that is common for both. So if I click on the button it will turn to 2.)

https://i.sstatic.net/Jwt0R.png


Solution

  • This is built-in to Google Play Game Services.

    Specifically the gms package com.google.android.gms.games.multiplayer.turnbased.

    You really don't need a timer to be built into the API because it is in the Android Core CountDownTimer class

    What you would do is you would set up the CountDownTimer and then for the onFinish() method, you would say to switch players turn.

    new CountDownTimer(30000, 1000) {
    
         public void onTick(long millisUntilFinished) {
             mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
         }
    
         public void onFinish() {
             mTextField.setText("done!");
         }
      }.start();