自动选择回合制比赛表现奇怪

时间:2017-02-23 15:00:02

标签: android-studio google-play-games multiplayer

我已经实现了基于回合制多人游戏的Android测验应用程序。奇怪的行为是当player1创建自动选择匹配并进行播放时,此游戏永远不会发送给其他玩家,即player2,因为我只有2个设备用于测试。现在我可以看到游戏正在等待从未到达过玩家2的对手。现在我从player2发送一个autopick匹配,这个匹配通过替换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();
}

1 个答案:

答案 0 :(得分:0)

如果您还没有这样做,您可能需要先访问Adding Turn-based Multiplayer Support to Your Android Game,其中建议您同时查看turn-based multiplayer game concepts

如上所列,在您开始编写基于回合制的多人游戏代码之前:

        

一旦玩家登录并且GoogleApiClient已连接,您的游戏就可以开始使用回合制多人游戏API。