Back to index

extremetuxracer  0.5beta
highscore.h
Go to the documentation of this file.
00001 /* 
00002  * PlanetPenguin Racer 
00003  * Copyright (C) 2004-2006 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 
00021 #ifndef _HIGHSCORE_H_
00022 #define _HIGHSCORE_H_
00023 
00024 #include <fstream>
00025 #include <string>
00026 
00027 #include "loop.h"
00028 #include "ppgltk/ui_mgr.h"
00029 #include "ppgltk/label.h"
00030 #include "ppgltk/listbox.h"
00031 #include "ppgltk/button.h"
00032 
00033 typedef struct{
00034        std::string highscore; 
00035        std::string name;
00036 }HighscoreData;
00037 
00038 class highscore
00039 {      
00040        private:
00041        static const int version = 2; //Highscore file version
00042        int findLevel(std::string level);
00043        void sort(int level);
00044        
00045        
00046        std::string toOutputFormat(std::string str);
00047        std::string fromOutputFormat(std::string str);
00048        
00049        public:
00050        highscore();
00051        
00052        static bool useHighscore;
00053        static bool hsDebug;
00054        static bool anyHighscore;
00055 
00056        struct
00057        scorepost {
00058               std::string nick;
00059               int score;
00060               scorepost() {
00061                      nick="";
00062                      score = 0;
00063               }
00064               std::string toString();
00065        };
00066        
00067        struct
00068        level_highscore {
00069               std::string level;
00070               scorepost post[10];
00071               int posts;
00072               level_highscore() {
00073                      level="";
00074                      posts=0;
00075               };
00076               
00077               
00078        };
00079        
00080        level_highscore *level_hs;
00081        int level_hs_length;
00082        
00083        int addScore(std::string level,std::string nick,int score);
00084        int posFromString(std::string level);
00085        std::list<std::string> getCourseList();
00086        std::list<HighscoreData> getCourseList_hd();
00087        static std::string posToStr(int pos);
00088        
00089        bool saveData();
00090        bool loadData();
00091        void debug();
00092        void printlist();
00093        void redim();
00094 };
00095 
00096 extern highscore* Highscore;
00097 
00098 class HighscoreShow
00099  : public GameMode
00100 {
00101        pp::Listbox<HighscoreData>* mp_raceListBox;
00102        std::list<HighscoreData> m_raceList;
00103        
00104        pp::Label* mp_titleLbl;
00105        pp::Label* mp_post[10];
00106        pp::Button* mp_backBtn;
00107        
00108 public:
00109        HighscoreShow();
00110        ~HighscoreShow();
00111 
00112        void loop(float timeStep);
00113 
00114        bool keyReleaseEvent(SDLKey key);
00115 
00116        void back();
00117        void updateStatus();
00118 };
00119 
00120 #endif // _HIGHSCORE_H_