2015-04-05 59 views
1

我正在使用Xamarin.Android和MonoGame制作Android游戏。我正在使用Google Play的TurnBasedMatch API来处理游戏的多人游戏方面。如何确定本地播放器是否赢得Google Play TurnBasedMatch?

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

令人惊讶的是,我一直无法找到TurnBasedMatch library的东西如果I赢得了比赛。我相信我一定会错过一些明显的东西。有没有人想出一个方法来确定这些信息?

谢谢!

回答

0

我能够通过扣除来解决这个限制。我的比赛只有2名球员,所以我用getDescriptionParticipant(“让参赛者代表比赛中的主要对手”)检查我的对手的名字,如果这是而不是获胜参与者的名字(我的游戏商店)然后我知道当地球员赢了。

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 
); 
相关问题