Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/Presentation_HS16/src/orxonox/Highscore.cc @ 12373

Last change on this file since 12373 was 11339, checked in by maxima, 8 years ago

merged the highscore branch to presentation

File size: 1.8 KB
Line 
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    }
19    /**
20     * @brief set the config values in the orxonox.ini file
21     */
22    void Highscore::setConfigValues()
23    {
24        SetConfigValue(highscores_, std::vector<std::string>()).description("Highscores saved as vector");
25        SetConfigValue(playerName_, "Player").description("Name of the player");
26    }
27    /**
28     * @brief Returns highest score of given game, if exists.
29     * Else returns -1.
30     */
31    int Highscore::getHighestScoreOfGame(std::string game){
32        std::string delimiter = "./."; //score save as "Playername./.game./.score"
33        int best = -1;
34        //check for the highest Score of given game
35        for (std::string score : this->highscores_)
36        {
37            //filter the game string from given highscore
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       
50    }
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));
56    }
57   
58}
Note: See TracBrowser for help on using the repository browser.