如何在Android Google Play服务的排行榜中增加玩家得分?

时间:2014-01-20 11:06:45

标签: android google-play-services leaderboard

我在Google Play服务中阅读了有关leaderboards的所有文档,似乎当我调用GameClient的submitScore函数时,该服务仅考虑提交的最高分数。 E.g:

第一个电话:

gamesclient.submitScore( 100 );

现在球员得分为100

第二次电话:

gamesclient.submitScore( 150 );

现在球员得分为150

第3次电话:

gamesclient.submitScore( 100 );

玩家得分仍然是150.提交的值不会超过最后一个,因此会被忽略。

是否有一种简单的方法可以检索最后一个玩家得分,总结新得分并提交总数以创建增量得分排行榜?像

这样的东西
int old_score = ...GET LAST PLAYER SCORE...
int new_score = old_score + current_game_score;
gamesclient.submitScore( new_score );

5 个答案:

答案 0 :(得分:4)

到目前为止没有测试过,但我认为这是要走的路:

    PendingResult<Leaderboards.LoadPlayerScoreResult> result = Games.Leaderboards.loadCurrentPlayerLeaderboardScore(gameHelper.getApiClient(),"LEADERBOARD_ID",LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
    result.setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
        @Override
        public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
            Games.Leaderboards.submitScore(gameHelper.getApiClient(), "LEADERBOARD_ID",loadPlayerScoreResult.getScore().getRawScore()+ score);
        }

答案 1 :(得分:1)

不幸的是,似乎没有一种内置的方法可以做到这一点。但是,您可以使用Cloud Save来保存播放器的最新分数,然后使用它。

或者,(这可能看起来有点俗气)每次提交分数时,将该分数保存在SharedPreferences中,然后当您提交另一分数时,使用该首选项增加分数而不是设置全新之一。

希望这有帮助,如果你真的不想解决问题,请告诉我,我会尝试找到另一种解决方案......

答案 2 :(得分:1)

这就是我想出来的......

@Override
    public void postNewScore(final int finalScore, final ArrayList<String> theseBoards) {
        //posts score update to any theseBoards... most likely 2 boards
        for (final String anID : theseBoards) {
            aHelper.getGamesClient().loadPlayerCenteredScores(new OnLeaderboardScoresLoadedListener() {

            @Override
            public void onLeaderboardScoresLoaded(int statusCode, Leaderboard leaderboard, LeaderboardScoreBuffer scores) {
                if(statusCode == GamesClient.STATUS_OK){
                    if(scores.getCount() == 0){
                        aHelper.getGamesClient().submitScore(anID, finalScore);
                        dLog("submitted a score because there were no scores period");
                    } else {
                        for (LeaderboardScore s : scores) {
                            if(s.getScoreHolder().getPlayerId().contains(aHelper.getGamesClient().getCurrentPlayer().getPlayerId()) ||
                                    aHelper.getGamesClient().getCurrentPlayer().getPlayerId().contains(s.getScoreHolder().getPlayerId())){
                                aHelper.getGamesClient().submitScore(anID, finalScore + s.getRawScore());
                                dLog("just submitted " + (finalScore + s.getRawScore()));
                                scores.close();
                                return;
                            }
                        }
                        //if to here, then no score on the current page, which means the player does not have a score
                        aHelper.getGamesClient().submitScore(anID, finalScore);
                        dLog("because no entry, just submitted " + (finalScore));
                    }
                } 
                scores.close();
            }
        }, anID, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_SOCIAL, 1);
        }

    }

答案 3 :(得分:0)

虽然您已经获得了如何增加分数的示例,但您无法将排行榜用作排名降低的排名表。

谷歌目前只允许该设施隐藏数十名疑似骗子。如果有某种方法可以降低分数或完全删除分数,那么你就可以按照自己的意愿去做。

我认为这背后的原因是,如果他们让你修改已经发布的分数,那么会削弱用户对Google Play游戏服务平台以及游戏中信任的信任 - 以扭曲玩家喜欢拥有的内容(原谅行话)。

随着时间的推移,这导致得分通胀,我认为他们在内部使用64位整数:

  /**
   * Submit a score to the 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.
   */
  void SubmitScore(std::string const &leaderboard_id, uint64_t score);

可以但是将排行榜的固定位置小数点位置修改为此通胀的课程调整。我不会。

很抱歉,如果这不是主题,请让Google在未来的更新中考虑这一点。

答案 4 :(得分:0)

如果有人仍在寻找解决方案,根据最新的android版本,可以按以下步骤进行操作:

private LeaderboardsClient mLeaderboardsClient = Games.getLeaderboardsClient(this, googleSignInAccount);    

private void updateLeaderboards(final String leaderboardId) {
        mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(
                leaderboardId,
                LeaderboardVariant.TIME_SPAN_ALL_TIME,
                LeaderboardVariant.COLLECTION_PUBLIC
        ).addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
            @Override
            public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
                if (leaderboardScoreAnnotatedData.get() == null)
                    mLeaderboardsClient.submitScore(leaderboardId, 1);
                else {
                    long currentscore = leaderboardScoreAnnotatedData.get().getRawScore();
                    mLeaderboardsClient.submitScore(leaderboardId, currentscore + 1);
                }
            }
        });
    }