【问题标题】:How to determine if Local Player won a Google Play TurnBasedMatch?如何确定本地玩家是否赢得了 Google Play TurnBasedMatch?
【发布时间】:2015-04-05 16:05:43
【问题描述】:
我正在使用 Xamarin.Android 和 MonoGame 制作 Android 游戏。我正在使用 Google Play 的 TurnBasedMatch API 来处理游戏的多人游戏方面。
在比赛结束时,我想确定本地玩家(在设备上登录 Google Play 的玩家)是否赢得了比赛。基本上,我希望能够说“你赢了!”或“你输了!”适当的。
令人惊讶的是,我无法在 TurnBasedMatch 库中找到任何东西来确定 我 是否赢得了比赛。我确定我一定遗漏了一些明显的东西。有没有人想出一种方法来确定这些信息?
谢谢!!
【问题讨论】:
标签:
android
google-play-services
google-play-games
【解决方案1】:
你可以这样做:
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
);