【问题标题】:Play game services, store custom scores玩游戏服务,存储自定义分数
【发布时间】:2014-03-25 08:48:05
【问题描述】:

我打算使用 Google Play 游戏服务来创建多人游戏。

我想为每个用户存储以下内容:

  • 比赛场次
  • 赢得比赛
  • 比赛中的最高分
  • 总分

我希望排行榜以降序显示最高分的数据。这可能吗?我可以提交多属性分数并在排行榜中显示吗?

格式可能有点像:

用户|玩过|赢得|最高|总数

用户1| 10 | 8 | 250 | 5000

用户2| 20 | 12| 225 | 5400

【问题讨论】:

    标签: google-play-games


    【解决方案1】:

    虽然可能,但并非没有一点开发时间。

    Google 使用排行榜存储了两个对保存分数很重要的东西:

    来自Google Developer

    public abstract void submitScore(GoogleApiClient apiClient, String leaderboardId, long score, String scoreTag)

    Submit a score to a leaderboard for the currently signed in player. The score is ignored if it is worse (as defined by the leaderboard configuration) than a previously submitted score for the same player.
    
    This form of the API is a fire-and-forget form. Use this if you do not need to be notified of the results of submitting the score, though note that the update may not be sent to the server until the next sync.
    
    The meaning of the score value depends on the formatting of the leaderboard established in the developer console. Leaderboards support the following score formats:
    
    Fixed-point: score represents a raw value, and will be formatted based on the number of decimal places configured. A score of 1000 would be formatted as 1000, 100.0, or 10.00 for 0, 1, or 2 decimal places.
    Time: score represents an elapsed time in milliseconds. The value will be formatted as an appropriate time value.
    Currency: score represents a value in micro units. For example, in USD, a score of 100 would display as $0.0001, while a score of 1000000 would display as $1.00
    

    有关详细信息,请参阅排行榜概念。

    Required API: API
    Required Scopes: SCOPE_GAMES
    
    Parameters
    apiClient   The GoogleApiClient to service the call.
    leaderboardId   The leaderboard to submit the score to.
    score   The raw score value.
    scoreTag    Optional metadata about this score. The value may contain no more than 64 URI-safe  characters as defined by section 2.3 of RFC 3986.
    

    因此,您可以使用 long 和 String 来存储您要保存的信息。但是,这也意味着您将无法使用 Google 排行榜显示方法。必须全部由您定制。

    例如,在存储/检索您的分数时,我会将长篇分成几个部分。 Long.MAX_VALUE = 9223372036854775807,因此您可以将其拆分为 Score/Won/Played(这样您的得分值仍然可以通过 Google 的检索系统对玩家进行正确排序),并且可能将最高得分存储在字符串中。 (随心所欲)

    因此,当您检索分数时,原始分数和 scoreTag 可能会存储为:

    User2 54000001200020   "225"
    User1 50000000800010   "250"
    

    现在,如果您的最高分数实际上是您想要的分数排序方式(如我在此处显示的副总分),则将其放在前面。

    然后,只需要拆分出每个乐谱部分,并格式化显示...

    【讨论】:

    • 我担心这是唯一的方法。感谢您的确认。我宁愿使用标签来存储 CSV 字符串和排序值,以便在 long 中使用。
    猜你喜欢
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 2018-10-05
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多