0

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

我们需要有关此问题的帮助。我们需要正确的玩家名称才能玩游戏。请检查随附的屏幕截图。

立即帮助将不胜感激。

4

1 回答 1

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
    }
于 2013-07-09T12:11:07.963 回答