Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoKart_HS18/src/orxonox/Highscore.cc @ 12397

Last change on this file since 12397 was 11783, checked in by landauf, 7 years ago

merged Presentation_HS17_merge back to trunk

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      kappenh
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Highscore.h"
30
31#include "core/CoreIncludes.h"
32#include "core/config/ConfigValueIncludes.h"
33#include "core/singleton/ScopedSingletonIncludes.h"
34#include "infos/PlayerInfo.h"
35#include "util/Convert.h"
36
37namespace orxonox
38{
39    ManageScopedSingleton(Highscore, ScopeID::ROOT, false);
40    RegisterClassNoArgs(Highscore);
41
42    Highscore::Highscore()
43    {
44        RegisterObject(Highscore);
45        this->setConfigValues();
46    }
47
48    /**
49     * @brief set the config values in the orxonox.ini file
50     */
51    void Highscore::setConfigValues()
52    {
53        SetConfigValue(highscores_, std::vector<std::string>()).description("Highscores saved as vector");
54    }
55
56    /**
57     * @brief Returns highest score of given game, if exists.
58     * Else returns -1.
59     */
60    int Highscore::getHighestScoreOfGame(const std::string& game)
61    {
62        const std::string delimiter = "./."; //score save as "Playername./.game./.score"
63        int best = -1;
64        //check for the highest Score of given game
65        for (std::string score : this->highscores_)
66        {
67            //filter the game string from given highscore
68            score.erase(0, score.find(delimiter) + delimiter.length());
69            if (game.compare(score.substr(0,score.find(delimiter))) == 0)
70            {
71                score.erase(0, score.find(delimiter) + delimiter.length());
72                int possibleBest = multi_cast<int>(score);
73                if (possibleBest > best)
74                    best = possibleBest;
75            }
76        }
77       
78        return best;
79       
80    }
81
82    /**
83     * @brief stores a new highscore in the orxonox.ini file if the new score is better than the highest score so far.
84     * @returns true if the given score marks a new high score
85     */
86    bool Highscore::storeScore(const std::string& level, int points, PlayerInfo* player)
87    {
88        if (points > this->getHighestScoreOfGame(level))
89        {
90            ModifyConfigValue(highscores_, add, player->getName() + "./." + level + "./." + multi_cast<std::string>(points));
91            return true;
92        }
93        else
94            return false;
95    }
96}
Note: See TracBrowser for help on using the repository browser.