Changeset 160


Ignore:
Timestamp:
09/27/2008 08:34:21 AM (4 years ago)
Author:
guyru
Message:

submit and check highscore

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/configuration.cpp

    r159 r160  
    277277        } 
    278278} 
     279 
     280bool Configuration::isHighscore(int score) { 
     281        const int highscore_list_size = atoi(m_settings["highscore-list-size"].c_str()); 
     282        if (m_highscores.size()<highscore_list_size) { 
     283                // we have extra room in the highscore list 
     284                return true; 
     285        } 
     286 
     287        HighscoreList::iterator it= m_highscores.end(); 
     288        if ((--it)->score<score) { 
     289                return true; 
     290        } 
     291 
     292        return false; 
     293} 
     294 
     295int Configuration::submitHighscore(int score, string name, string date) { 
     296        const int highscore_list_size = atoi(m_settings["highscore-list-size"].c_str()); 
     297        int place = 1; 
     298        HighscoreItem temp_item; 
     299 
     300        //create sentinel in end of list, we'll remove when we finish 
     301        temp_item.score = -1; // this is lower than any valid score 
     302        m_highscores.push_back(temp_item); 
     303 
     304        temp_item.score = score; 
     305        temp_item.date = date; 
     306        temp_item.name = name; 
     307 
     308        HighscoreList::iterator it = m_highscores.begin(); 
     309        while (it!=m_highscores.end()) { 
     310                if (it->score < temp_item.score) { 
     311                        m_highscores.insert(it, temp_item); 
     312                        break; 
     313                } 
     314                place++; 
     315                it++; 
     316        } 
     317        m_highscores.pop_back(); // remove the sentinel; 
     318 
     319        if (m_highscores.size()>highscore_list_size) { 
     320                m_highscores.pop_back(); 
     321        } 
     322 
     323        if (place>highscore_list_size) { 
     324                return 0; 
     325        } 
     326        return place; 
     327} 
  • trunk/src/configuration.h

    r159 r160  
    6161         */ 
    6262        Configuration *set(std::string key, std::string value); 
     63 
     64        bool isHighscore(int score); 
     65        int submitHighscore(int score, std::string name, std::string date); 
    6366private: 
    6467        /** 
Note: See TracChangeset for help on using the changeset viewer.