基于回合制的多人游戏应用程序两个玩家都无法转弯

时间:2014-02-07 06:52:27

标签: android google-play-services

当我点击我的国际象棋应用程序上的播放!时,会将您带到选择播放器屏幕,如此...

注意:mGamesClient是使用GameClient连接的mGamesClient.connect()

Intent intent = mGamesClient.getSelectPlayersIntent(1, 1, true);
        startActivityForResult(intent, RC_SELECT_PLAYERS);

现在我选择了我的播放器(只有一个播放器,因为它是国际象棋)后,我得到onActivityResult回调,看起来像这样......

@Override
    public void onActivityResult(int request, int response, Intent data) {
        super.onActivityResult(request, response, data);

        if (request == RC_SELECT_PLAYERS) {
            if (response != Activity.RESULT_OK) {
                // user canceled
                return;
            }

            // get the invitee list
            final ArrayList<String> invitees = data
                    .getStringArrayListExtra(GamesClient.EXTRA_PLAYERS);

            // get auto-match criteria
            Bundle autoMatchCriteria = null;
            int minAutoMatchPlayers = data.getIntExtra(
                    GamesClient.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
            int maxAutoMatchPlayers = data.getIntExtra(
                    GamesClient.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();

            // kick the match off
            mGamesClient.createTurnBasedMatch(this, tbmc);
        }

        Log.v("LOG", "+++ ONACTIVITYRESULT HOMESCREENACTIVITY +++");
    }

现在因为mGamesClient.createTurnBasedMatch(this, tbmc);被调用,我得到一个onTurnBasedMatchInitiated回调,看起来像这样......

@Override
    public void onTurnBasedMatchInitiated(int statusCode, TurnBasedMatch match) {
        Log.v("LOG", "+++ ONTURNBASEDMATCHINITIATED HOMESCREENACTIVITY +++");
        mMatch = match;
        // Check if the status code is not success;
        if (statusCode != GamesClient.STATUS_OK) {
            showErrorMessage(statusCode);
            Log.v("LOG", "" + statusCode);
            return;
        }

            Intent i = new Intent(getApplicationContext(), OfflineInGameActivity.class);
            i.putExtra("soundOn", soundOn);
            i.putExtra("LoLImages", LoLImages);
            startActivity(i);
            return;
    }

现在我的国际象棋活动开始了。在我的对手方面,他/她收到了一个邀请,如果被接受,将拨打acceptTurnBasedInvitation

现在我的问题是,没有一个球员可以采取行动,因为每个球员都说不是轮到他们了。