2017-02-23 68 views
0

我已經實現了基於turnbased多人遊戲的android測驗應用程序。奇怪的行爲是,當player1創建一個自動選擇匹配並進行遊戲時,這個遊戲永遠不會發送給其他玩家,即player2,因爲我只有2個設備進行測試。現在我可以看到遊戲正在等待從未到達player2的對手。現在我發送一個來自player2的自動挑選比賽,並且通過替換player1發送的比賽將該比賽發送給player1,並且它變成我在player1上的轉身,並且他可以正常地進行比賽。如何解決這個問題?自動挑選基於回合的比賽表現奇怪

@Override 
public void onActivityResult(int request, int response, Intent data) { 
    super.onActivityResult(request, response, data); 
    dismissSpinner(); 
    if (request == RC_LOOK_AT_MATCHES) { 
     // Returning from the 'Select Match' dialog 
     if (response != Activity.RESULT_OK) { 
      // user canceled 
      return; 
     } 
     TurnBasedMatch match = data 
       .getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH); 

     if (match != null) { 
      //update match here 
      updateMatch(match); //Pls ignore this nothing happen here, still under development 
     } else { 
      // Toast.makeText(getApplicationContext(), "finish", Toast.LENGTH_LONG).show(); 
     } 
    } else if (request == RC_SELECT_PLAYERS) { 
     // Returned from 'Select players to Invite' dialog 
     if (response != Activity.RESULT_OK) { 
      // user canceled 
     } 
     else{ 
      startNewMatchWithIntent(data); 
     } 

    } 
} 

private void startNewMatchWithIntent(Intent intent) 
{ 
    // Log.d("activityResult", "ResultOK"); 
    // get the invitee list 
    final ArrayList<String> invitees = intent 
      .getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); 
    // get automatch criteria 
    Bundle autoMatchCriteria = null; 

    int minAutoMatchPlayers = intent.getIntExtra(
      Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); 
    int maxAutoMatchPlayers = intent.getIntExtra(
      Multiplayer.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(); 

    // Start the match 
    Games.TurnBasedMultiplayer.createMatch(mGoogleApiClient, tbmc).setResultCallback(
      new ResultCallback<TurnBasedMultiplayer.InitiateMatchResult>() { 

       @Override 
       public void onResult(@NonNull TurnBasedMultiplayer.InitiateMatchResult result) { 
        dismissSpinner(); 
        processResult(result); 
        Log.d(TAG, "create match :" + String.valueOf(result.getMatch().getDescriptionParticipant())); 
       } 
      }); 
    showSpinner(); 
} 
+0

這是不可能沒有看到任何代碼來回答這個問題。請參閱http://stackoverflow.com/help/mcve –

+0

添加的代碼塊。請看一下。 –

回答

0

如果您還沒有這樣做,你可能需要先訪問Adding Turn-based Multiplayer Support to Your Android Game其中有人建議也回顧turn-based multiplayer game concepts

所列舉的,你開始編寫你的回合制多人遊戲之前:在谷歌Play開發者控制檯

一旦玩家登錄並且GoogleApiClient已連接,您的遊戲就可以開始使用基於回合的多人遊戲API。