Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/Highscore.cc @ 11716

Last change on this file since 11716 was 11716, checked in by landauf, 8 years ago

[Highscore_HS16] moved logic to compare old an new score to Highscore; fixed formatting in Gametypes

File size: 1.9 KB
RevLine 
[11313]1#include "Highscore.h"
2
3#include "core/CoreIncludes.h"
4#include "core/config/ConfigValueIncludes.h"
5#include "core/singleton/ScopedSingletonIncludes.h"
[11715]6#include "infos/PlayerInfo.h"
7#include "util/Convert.h"
[11313]8
9namespace orxonox
10{
11    ManageScopedSingleton(Highscore, ScopeID::ROOT, false);
12        RegisterClassNoArgs(Highscore);
13
14        Highscore::Highscore()
15    {
16        RegisterObject(Highscore);
17        this->setConfigValues();
18    }
[11715]19
[11333]20    /**
21     * @brief set the config values in the orxonox.ini file
22     */
[11313]23    void Highscore::setConfigValues()
24    {
[11333]25        SetConfigValue(highscores_, std::vector<std::string>()).description("Highscores saved as vector");
[11315]26    }
[11715]27
[11333]28    /**
29     * @brief Returns highest score of given game, if exists.
30     * Else returns -1.
31     */
[11715]32    int Highscore::getHighestScoreOfGame(const std::string& game){
33        const std::string delimiter = "./."; //score save as "Playername./.game./.score"
[11315]34        int best = -1;
[11333]35        //check for the highest Score of given game
[11315]36        for (std::string score : this->highscores_)
37        {
[11333]38            //filter the game string from given highscore
[11315]39            score.erase(0, score.find(delimiter) + delimiter.length());
40            if(game.compare(score.substr(0,score.find(delimiter))) == 0){
41                score.erase(0, score.find(delimiter) + delimiter.length());
[11715]42                int possibleBest = multi_cast<int>(score);
[11315]43                if(possibleBest > best) best = possibleBest;
44            }
45        }
46       
47        return best;
48       
[11313]49    }
[11715]50
[11333]51    /**
[11716]52     * @brief stores a new highscore in the orxonox.ini file if the new score is better than the highest score so far.
[11333]53     */
[11716]54    void Highscore::storeScore(const std::string& level, int points, PlayerInfo* player){
55        if (points > this->getHighestScoreOfGame(level)) {
56            ModifyConfigValue(highscores_, add, player->getName() + "./." + level + "./." + multi_cast<std::string>(points));
57        }
[11313]58    }
59}
Note: See TracBrowser for help on using the repository browser.