Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11524 was 11356, checked in by patricwi, 8 years ago

merged space race with trunk

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