0
我想在使用Google Play遊戲的Android中編寫多人遊戲。一切正在爲自動匹配工作,但我無法弄清楚如何決定何時開始邀請遊戲。谷歌玩遊戲:從邀請ID獲取請求玩家的總數
我的網絡管理器有這樣的shouldStartGame()函數:
boolean shouldStartGame(Room room)
{
int connectedPlayers = 0;
for (Participant p : room.getParticipants()) {
if (p.isConnectedToRoom()) ++connectedPlayers;
}
return connectedPlayers >= this.totalRequestedPlayers;
}
當遊戲是一個自動配對遊戲,這是好的 - totalRequestedPlayers獲取onActivityResult,當玩家選擇對話框返回一個填充
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);
}
}
我需要找出從原始邀請「命名爲」玩家總數,加上自動配對的數量要求