Android Play游戏:自定义房间配置,具有灵活的玩家数量

sky*_*ium 11 android real-time multiplayer google-play-services google-play-games

我正在开发一个实时多人游戏.游戏本身运作良好.我正在努力与房间配置.我使用谷歌玩游戏作为框架.游戏概念是为单个房间管理从2到7的玩家数量.这场比赛是一场棋盘游戏.因此,如果连接很多玩家,那就更好了.否则游戏会很无聊.我有可能使用谷歌AutoMatchCriteria进行配对:

final int MIN_OPPONENTS = 1, MAX_OPPONENTS = 6;
Bundle autoMatchCriteria = RoomConfig
    .createAutoMatchCriteria(MIN_OPPONENTS, MAX_OPPONENTS, 0);
RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
....
Run Code Online (Sandbox Code Playgroud)

如果我设置MIN_OPPONENTS = 1并且MAX_OPPONENTS = 6,那么在大多数情况下,游戏将以2名玩家开始.在SO-Thread中,谷歌开发者提到:

自动匹配算法不会非常努力地最大化匹配中的玩家数量......

我也可以使用MIN_OPPONENTS = 6和MAX_OPPONENTS = 6.通过此设置,只有7个玩家连接到房间时才会启动游戏.我的游戏提供了许多游戏变体和很多难度级别.因此我假设并不总是有7名球员可用.我需要一个灵活的解决方案,始终保证游戏开始.

同一个谷歌人使用计时器描述了一个解决方案:SO-Thread

我不知道从这个概念开始.我应该在哪里启动计时器?有没有人成功实现这个概念?如果这个人可以分享一些代码片段或者向我提供一些进一步的解释,那将是非常好的.其他建议也是受欢迎的.

更新2019年:仍在寻找改进.请给出提示.

我的gradle文件包含:

implementation 'com.google.android.gms:play-services-appstate:6.5.87'
implementation 'com.google.android.gms:play-services-games:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-ads:16.0.0'
Run Code Online (Sandbox Code Playgroud)

这就是我开始多人游戏的方式:

    void startQuickGame() {
    final int MAX_OPPONENTS = 6;
    int min_opponents = 1;
    Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(min_opponents,
            MAX_OPPONENTS, 0);
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    rtmConfigBuilder.setVariant(variant);
    switchToScreen(R.id.mpGamescreen_wait);
    keepScreenOn();

    Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());
    }
Run Code Online (Sandbox Code Playgroud)

我在这里找到一个提示:在使用Google Play游戏服务机器人成功创建房间后强行启动游戏 他们提到了一些自定义计时器.