玩游戏服务,存储自定义分数

时间:2014-03-25 08:48:05

标签: google-play-games

我打算使用Google Play游戏服务来制作多人游戏。

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

  • 比赛
  • 赢得比赛
  • 比赛中得分最高
  • 总分

我希望排行榜按降序显示数据以获得最高分。这可能吗?我可以提交多属性分数并将其显示在领导委员会中吗?

格式可能有点像:

用户|玩过|赢得|最高|共

用户1 | 10 | 8 | 250 | 5000

用户2 | 20 | 12 | 225 | 5400

1 个答案:

答案 0 :(得分:2)

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

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 Leaderboard显示方法。必须全部由您自定义。

例如,在存储/检索你的分数时,我会分解很长的部分。 Long.MAX_VALUE = 9223372036854775807,因此您可以将其拆分为Score / Won / Played(这样您的得分值仍然可以通过Google的检索系统正确地对玩家进行排序)并且可能会在String中存储最高得分。 (用你可能想要的任何其他东西)

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

User2 54000001200020   "225"
User1 50000000800010   "250"

现在,如果你的最高点实际上是你想要的分数排序(像我在这里显示的副总数),那么坚持在前面。

然后,只需要打破每个得分部分,并格式化显示......