邀请的自动选择选项上的玩家姓名

时间:2013-07-08 11:41:08

标签: multiplayer google-play-services

我们使用Google Play服务开发了一款多人游戏。 当我们向api发送请求以邀请朋友玩游戏时,点击自动选择时,对手的名字不显示,而是列表显示任何随机名称,如Player_1231,Player_3333等。

我们需要有关此问题的帮助。我们需要适当的玩家名称才能玩游戏。请查看附带的截图。

我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

请找到以下代码:

public void onRoomConnected(int statusCode, Room room) {
        // TODO Auto-generated method stub
        if (statusCode != mGamesClient.STATUS_PARTICIPANT_NOT_CONNECTED) {
            // Toast.makeText(this, " is PARTICIPANT_CONNECTED.",
            // Toast.LENGTH_SHORT).show();
            roomId = room.getRoomId();
            room_creator_id = room.getCreatorId();
            // participantId = p.getParticipantId();
            current_player_id = room.getParticipantId(mGamesClient
                    .getCurrentPlayerId());
            Asset.self = Asset.username;
            if (room_creator_id != null) {
                if (room_creator_id.equals(current_player_id)) {
                    Server = true;
                }
            }
            // Toast.makeText(this,
            // " is PARTICIPANT_CONNECTED."+room_creator_id,
            // Toast.LENGTH_SHORT).show();
            par = null;
            par = room.getParticipants();

            for (Participant p : par) {

                if (!p.getParticipantId().equals(current_player_id)) {
                    System.out.println(current_player_id
                            + "  After 1 connect   " + p.getParticipantId());
                    participantId = p.getParticipantId();
                    Asset.opponent = p.getDisplayName();

                    break;
                }
            }
            menu.initPage(GameConst.SELECTLEVEL_PAGE_ONLINE);
            menu.Start_Selection_Timer();

        }

        // Toast.makeText(this, " is onRoomConnected.",
        // Toast.LENGTH_SHORT).show();
    }




    PLAY ONLINE---------------

    public void startQuickGame() {
        // automatch criteria to invite 1 random automatch opponent.
        // You can also specify more opponents (up to 3).
        if (mGamesClient.isConnected()) {
            Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);

            // build the room config:
            RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
            roomConfigBuilder.setAutoMatchCriteria(am);
            RoomConfig roomConfig = roomConfigBuilder.build();

            // create room:

            mGamesClient.createRoom(roomConfig);
        } else {
            Toast.makeText(con, "Wait for connection or try after some time",
                    Toast.LENGTH_SHORT).show();
            mGamesClient.connect();
        }

        // go to game screen
    }