Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12012 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
RevLine 
[11717]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
[11313]29#include "Highscore.h"
30
31#include "core/CoreIncludes.h"
32#include "core/config/ConfigValueIncludes.h"
33#include "core/singleton/ScopedSingletonIncludes.h"
[11715]34#include "infos/PlayerInfo.h"
35#include "util/Convert.h"
[11313]36
37namespace orxonox
38{
39    ManageScopedSingleton(Highscore, ScopeID::ROOT, false);
[11717]40    RegisterClassNoArgs(Highscore);
[11313]41
[11717]42    Highscore::Highscore()
[11313]43    {
44        RegisterObject(Highscore);
45        this->setConfigValues();
46    }
[11715]47
[11333]48    /**
49     * @brief set the config values in the orxonox.ini file
50     */
[11313]51    void Highscore::setConfigValues()
52    {
[11333]53        SetConfigValue(highscores_, std::vector<std::string>()).description("Highscores saved as vector");
[11315]54    }
[11715]55
[11333]56    /**
57     * @brief Returns highest score of given game, if exists.
58     * Else returns -1.
59     */
[11717]60    int Highscore::getHighestScoreOfGame(const std::string& game)
61    {
[11715]62        const std::string delimiter = "./."; //score save as "Playername./.game./.score"
[11315]63        int best = -1;
[11333]64        //check for the highest Score of given game
[11315]65        for (std::string score : this->highscores_)
66        {
[11333]67            //filter the game string from given highscore
[11315]68            score.erase(0, score.find(delimiter) + delimiter.length());
[11717]69            if (game.compare(score.substr(0,score.find(delimiter))) == 0)
70            {
[11315]71                score.erase(0, score.find(delimiter) + delimiter.length());
[11715]72                int possibleBest = multi_cast<int>(score);
[11717]73                if (possibleBest > best)
74                    best = possibleBest;
[11315]75            }
76        }
77       
78        return best;
79       
[11313]80    }
[11715]81
[11333]82    /**
[11716]83     * @brief stores a new highscore in the orxonox.ini file if the new score is better than the highest score so far.
[11783]84     * @returns true if the given score marks a new high score
[11333]85     */
[11783]86    bool Highscore::storeScore(const std::string& level, int points, PlayerInfo* player)
[11717]87    {
88        if (points > this->getHighestScoreOfGame(level))
89        {
[11716]90            ModifyConfigValue(highscores_, add, player->getName() + "./." + level + "./." + multi_cast<std::string>(points));
[11783]91            return true;
[11716]92        }
[11783]93        else
94            return false;
[11313]95    }
96}
Note: See TracBrowser for help on using the repository browser.