【问题标题】:How can I get my own Participant ID in a TurnBasedMatch?如何在 TurnBasedMatch 中获得我自己的参与者 ID?
【发布时间】:2014-07-16 19:42:55
【问题描述】:

我知道我可以使用 TurnBasedMatch.getParticipants() 获取所有参与者,并且我知道我可以在轮到玩家时通过 TurnBasedMatch.getPendingParticipantId() 获取玩家的参与者 id,但是我如何获取参与者对象或 id如果不是轮到玩家?我当然可以在轮到我的时候把它保存在本地,然后再阅读,但是有没有更好的方法?

【问题讨论】:

    标签: android google-play-games


    【解决方案1】:

    我和我的朋友用这个开发了一个国际象棋游戏,他用java到Android,我用objective-c到iOS,他这样做是为了让玩家:

    Games.Players.getCurrentPlayer(getApiClient())
    

    那么就可以通过播放器获取playerID或者participantID...

    【讨论】:

    • @ThomasdH 您是如何从 GMS.Games.Player 对象中获取 ParticipantID 的?如果我尝试使用该 PlayerID 调用 GetParticipant,它会失败(“参与者 108961654314219883302 与 ChEKCQje4PTRxRoQAhACGAAgARDi1J2_9Yqbi8EB 不匹配”)
    • 我猜你只能在没有结束的比赛中调用它
    • 即使在未完成的比赛中,我也会遇到同样的异常。我相信这可能是因为我向它传递了一个 playerID,但该函数需要一个参与者 ID(我认为它们是不同的)。
    • TurnBasedMatch 对象有一个方法:getParticipantId()。只需传递玩家 ID 即可获取参与者 ID。
    【解决方案2】:
    public String myParticipantID(){
        return match.getParticipantId(Games.Players.getCurrentPlayer(gac).getPlayerId());
    }
    

    gac 是您的 GoogleApiClient 对象

    【讨论】:

    • 这是获取participantID的正确方法,而不是批准的答案。
    猜你喜欢
    • 1970-01-01
    • 2010-09-07
    • 2018-05-26
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 2022-10-20
    相关资源
    最近更新 更多