google play games:从邀请ID中获取请求的玩家总数

Posted

技术标签:

【中文标题】google play games:从邀请ID中获取请求的玩家总数【英文标题】:google play games: get the total amount of requested players from an invitation id 【发布时间】:2016-04-07 03:55:09 【问题描述】:

我正在尝试使用 Google Play Games 在 android 中编写多人游戏。一切都适用于自动机,但我不知道如何决定何时开始邀请游戏。

我的网络管理器有一个 shouldStartGame() 函数,如下所示:

boolean shouldStartGame(Room room) 

    int connectedPlayers = 0;
    for (Participant p : room.getParticipants()) 
        if (p.isConnectedToRoom()) ++connectedPlayers;
    
    return connectedPlayers >= this.totalRequestedPlayers;

When the game is a automatch game, this is fine - totalRequestedPlayers gets populated in onActivityResult, when the Select Players dialog returns

public void onActivityResult(int request, int response, Intent data) 
if (request == NetworkManager.RC_SELECT_PLAYERS)

final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);

if (minAutoMatchPlayers > 0) 

    autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
            minAutoMatchPlayers, maxAutoMatchPlayers, 0);
 
else 

    autoMatchCriteria = null;


this.oNetwork.setTotalRequestedPlayers(invitees.size() + minAutoMatchPlayers);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);

// prevent screen from sleeping during handshake
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

但是,当响应其他玩家的邀请开始比赛时,我找不到任何方法可以询问房间或 configBuilder 以确定需要多少玩家...

protected void onCreate(Bundle _savedState)
   
String invitationID=this.getIntent().getExtras().getString(NetworkManager.EXTRA_ROOM_ID);
if(invitationID.equals(""))

    //invite some people
    this.oNetwork.beginInviteFriends(); 

else

//we have been invited to a room
    RoomConfig.Builder roomConfigBuilder =
            this.oNetwork.makeStandardRoomConfigForGameType(this);
    roomConfigBuilder.setInvitationIdToAccept(invitationID);

    RoomConfig c = roomConfigBuilder.build();

    this.oNetwork.setTotalRequestedPlayers(999);  // <-  need to figure out how to get this info
    Games.RealTimeMultiplayer.join(getApiClient(), c);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


我需要从原始邀请中找出“指定”玩家的总数,以及自动匹配请求的数量

【问题讨论】:

【参考方案1】:

功能

@Override
public void onRoomConnected(int arg0, Room _room)



在所有用户(无论是受邀用户还是自动匹配用户)都连接到会议室时通知您。

【讨论】:

以上是关于google play games:从邀请ID中获取请求的玩家总数的主要内容,如果未能解决你的问题,请参考以下文章

从 Google Play Games API 获取用户 ID?

Google Play 游戏服务 2017:如何邀请某人参加多人比赛?

如何从 Android 中的 Google Play Games API 中提取多个排行榜?

100% “google.play.games.games.v1.Applications.RecordApplicationActivity” 一个月以来

如何访问 Google Play 游戏玩家 ID

Google play 游戏服务邀请丢失