【问题标题】:google play games: get the total amount of requested players from an invitation idgoogle play games:从邀请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);
}
}

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

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    功能

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 2015-03-06
      • 2015-01-02
      • 2018-06-14
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多