我正在尝试使用Google Play游戏在Android中编写多人游戏。一切都适用于自动匹配,但我无法弄清楚如何决定何时开始邀请游戏。
我的网络管理员有一个像这样的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);
}
}
我需要找出被命名的&#39;的总数。来自原始邀请的玩家,加上自动匹配请求的数量
答案 0 :(得分:0)
功能
@Override
public void onRoomConnected(int arg0, Room _room)
{
}
告诉您所有被邀请或自动匹配的用户是否已连接到会议室。