2014-02-14 26 views
2

我正在開發基於turnbased的多人android應用程序。如何使用這個新聽衆

起初,我不得不實施TurnBasedMultiplayerListener並覆蓋onTurnBasedMatchInitiated但現在的接口已被棄用,我需要使用this listener

的問題是,我不知道如何使用它。我已經讓我的類實現了接口,並且我已經重寫了這些方法。

然後創建一個turnBasedGame如下...

PendingResult<InitiateMatchResult> f = 
    Games.TurnBasedMultiplayer.createMatch(gApiClient, tbmc); 

現在我想我不得不說f.setResultCallback(...),但我不知道它裏面放什麼。

有什麼建議嗎?

回答

2

您將需要給一個實現了ResultCallback作爲參數的類。

public void MatchInitiatedCallback implements ResultCallback { 

    @Override 
    public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) { 
     // Check if the status code is not success; 
     if (result.getStatus != GamesStatusCodes.STATUS_OK) { 
      showError(statusCode); 
      return; 
     } 

     TurnBasedMatch match = result.getMatch(); 

     // If this player is not the first player in this match, continue. 
     if (match.getData() != null) { 
      showTurnUI(match); 
      return; 
     } 

     // Otherwise, this is the first player. Initialize the game state. 
     initGame(match); 

     // Let the player take the first turn 
     showTurnUI(match); 
    } 
} 

參考:https://developers.google.com/games/services/android/turnbasedMultiplayer#selecting_players_with_the_default_user_interface

+0

我已經試過了之前。它說無效是一個無效的類型MatchInitiatedCallback – Ogen

+0

沒關係,我修復它 – Ogen