无法关闭 Google Play Games 的回合制多人游戏

Cannot close turnbased multiplayer match with Google Play Games

我在最后一位玩家结束最后一场比赛后关闭我的游戏时遇到问题。我的回合方案是:

  1. 选手A
  2. 选手B
  3. 选手B
  4. 选手A
  5. 选手A
  6. 选手B

游戏运行良好,但当玩家 B 尝试结束比赛时,玩家 A 总是将 matsh 视为 "my turn" 而不是 "completed"

这里是规则回合和游戏结束的代码:

@Override
    public void onGameEnd(final NMXGameData updatedData) {
        super.onGameEnd(updatedData);

        if (updatedData.getMatchNumber() == NMXGameConfig.MATCHES) {
            boolean iWin = updatedData.getResultPoints()[1] > updatedData.getResultPoints()[0];
            boolean tile = updatedData.getResultPoints()[1] == updatedData.getResultPoints()[0];

            ParticipantResult opponentParticipantResult;
            ParticipantResult myParticipantResult;

            if (tile) {
                opponentParticipantResult = new ParticipantResult(getOpponentId(), ParticipantResult.MATCH_RESULT_TIE, 1);
                myParticipantResult = new ParticipantResult(getCurrentPlayerId(), ParticipantResult.MATCH_RESULT_TIE, 1);
            } else {
                if (iWin) {
                    opponentParticipantResult = new ParticipantResult(getOpponentId(), ParticipantResult.MATCH_RESULT_LOSS, 2);
                    myParticipantResult = new ParticipantResult(getCurrentPlayerId(), ParticipantResult.MATCH_RESULT_WIN, 1);
                } else {
                    opponentParticipantResult = new ParticipantResult(getOpponentId(), ParticipantResult.MATCH_RESULT_WIN, 1);
                    myParticipantResult = new ParticipantResult(getCurrentPlayerId(), ParticipantResult.MATCH_RESULT_LOSS, 2);
                }
            }

            ArrayList<ParticipantResult> participantResultArrayList = new ArrayList<>();
            participantResultArrayList.add(opponentParticipantResult);
            participantResultArrayList.add(myParticipantResult);

            Games.TurnBasedMultiplayer.finishMatch(getApiClient(), match.getMatchId(), new Gson().toJson(updatedData).getBytes(), opponentParticipantResult, myParticipantResult).setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
                @Override
                public void onResult(TurnBasedMultiplayer.UpdateMatchResult updateMatchResult) {
                    finish();
                }
            });

        } else if (updatedData.getMatchNumber() < NMXGameConfig.MATCHES) {

            if (getNextPlayerIndex(updatedData.getMatchNumber()) != getNextPlayerIndex(updatedData.getMatchNumber() - 1)) {
                Games.TurnBasedMultiplayer.takeTurn(getApiClient(), match.getMatchId(), new Gson().toJson(updatedData).getBytes(), getNextParticipantId());
            } else {
                Games.TurnBasedMultiplayer.takeTurn(getApiClient(), match.getMatchId(), new Gson().toJson(updatedData).getBytes(), getCurrentPlayerId());
                startActivity(startNewOnlineGameIntent(this, updatedData, match.getMatchId()));
            }
            finish();
        }


    }

    private String getCurrentPlayerId() {
        return match.getParticipantId(Games.Players.getCurrentPlayerId(getApiClient()));

    }

    private String getOpponentId() {
        for (String id : match.getParticipantIds()) {
            if (!id.equals(getCurrentPlayerId())) {
                return id;
            }
        }
        return null;
    }

    private int getNextPlayerIndex(int nextRoundIndex) {
        nextRoundIndex = nextRoundIndex + 1;
        return (nextRoundIndex / 2) % 2;
    }

终于想通了

我不知道这是否是所需的行为,但是在第 6 轮 player_B 调用时:

Games.TurnBasedMultiplayer.finishMatch(getApiClient(), match.getMatchId(), new Gson().toJson(updatedData).getBytes(), opponentParticipantResult, myParticipantResult).setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
                @Override
                public void onResult(TurnBasedMultiplayer.UpdateMatchResult updateMatchResult) {
                    finish();
                }
            });

轮到 player_A,将那场比赛视为 "my turn"。此时玩家A必须调用Games.TurnBasedMultiplayer.finishMatch(getApiClient(), match.getMatchId())(没有玩真正的游戏)并且游戏对两个玩家都完成