gpt4 book ai didi

android - 如何确定本地玩家是否赢得了 Google Play TurnBasedMatch?

转载 作者:行者123 更新时间:2023-11-29 01:34:15 25 4
gpt4 key购买 nike

我正在使用 Xamarin.Android 和 MonoGame 制作 Android 游戏。我正在使用 Google Play 的 TurnBasedMatch用于处理游戏的多人游戏方面的 API。

在比赛结束时,我想确定本地玩家(在设备上登录 Google Play 的玩家)是否赢得了比赛。基本上,我希望能够说“你赢了!”或“你输了!”适本地。

令人惊讶的是,我无法在 TurnBasedMatch 库中找到任何东西来确定是否赢得了比赛。我确定我一定遗漏了一些明显的东西。有没有人找到确定这些信息的方法?

谢谢!!

最佳答案

你可以这样做:

String localPlayerId = Games.Players.getCurrentPlayerId( getApiClient());   
Participant localParticipant = mMatch.getParticipant( mMatch.getParticipantId( localPlayerId));
ParticipantResult result = localParticipant.getResult();

if (result != null && result.getResult() == ParticipantResult.MATCH_RESULT_WIN) {
// Local player won, show greetings...
}

注意:要使其正常工作,您之前必须调用 finishMatch(..),参与者结果如下:

List<ParticipantResult> participantResults = new ArrayList<ParticipantResult>();
participantResults.add( new ParticipantResult( participantId1, ParticipantResult.MATCH_RESULT_WIN, 1));
participantResults.add( new ParticipantResult( participantId2, ParticipantResult.MATCH_RESULT_LOSS, 2));

Games.TurnBasedMultiplayer.finishMatch(
getApiClient(),
mMatch.getMatchId(),
gameData,
participantResults
);

关于android - 如何确定本地玩家是否赢得了 Google Play TurnBasedMatch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com