【问题标题】: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
    );
    

    【讨论】:

      【解决方案2】:

      我能够通过扣除来解决这个限制。我的游戏只有 2 名玩家,所以我使用 getDescriptionParticipant(“获取代表比赛中主要对手的参与者。”)检查我的对手的名字,如果那是不是的名字获胜的参与者(我的游戏存储)然后我知道本地玩家赢了。

      【讨论】:

        猜你喜欢
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        • 2019-09-17
        • 1970-01-01
        • 2016-11-27
        • 2016-07-10
        • 2016-10-04
        • 1970-01-01
        相关资源
        最近更新 更多