如何限制到最大Google Play游戏服务排行榜API提交1x评分?

时间:2015-06-04 09:37:46

标签: android google-play-services google-play-games leaderboard

我的应用正在使用Google Play游戏服务排行榜API。 到目前为止,一切似乎都很好。

我现在不知道如何设定如何为每位玩家设置分数提交的最大限制。 我不是在谈论在排行榜上只显示用户一个最好的分数!!!

这一个特定的排行榜是基于玩家第一次打分! 我想让每个人都只有最大限度。一杆即可获得最佳得分。一旦他们的分数被提交,绝对没有办法提交更好的分数!!!

我该怎么做?我知道我可以通过sharedPrefs使用布尔值来实现这个糟糕的方法,但这只有在播放器不重新安装应用程序或清除应用程序数据时才有效。

我不知道如何做到这一点。我希望Google Play游戏服务中有一些神奇的技巧我可以使用,否则我需要在线完成 - 从服务器上传和下载变量。我真的希望我不必这样,任何有更好解决方案的人都会这样做吗?

由于

1 个答案:

答案 0 :(得分:1)

我认为最好的解决方案是两者都做:) 提交分数后,使用本地sharedPrefs,可以比使用loadCurrentPlayerLeaderboardScore()

之类的东西更快地检查服务器
if (lastSubmittedScore() == null) { // read from local prefs, null if not set.
    // call Server
    PendingResult<Leaderboards.LoadPlayerScoreResult> result =
        Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, leaderboardId,
        TIME_SPAN_ALL_TIME, COLLECTION_PUBLIC);

    if (result.await().getScore() == null) {
        // no score - submit it
        Games.Leaderboards.submitScore(mGoogleApiClient,leaderboardId, firstScore);
        // write out locally, that we scored
        saveLastSubmittedScore(firstScore);
    }
}