1 /*
2     Bastet - tetris clone with embedded bastard block chooser
3     (c) 2005-2009 Federico Poloni <f.polonithirtyseven@sns.it> minus 37
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CONFIG_HPP
20 #define CONFIG_HPP
21 
22 #include <vector>
23 #include <string>
24 #include <boost/array.hpp>
25 
26 namespace Bastet{
27 
28   struct Keys{
29     int Down;
30     int Left;
31     int Right;
32     int RotateCW;
33     int RotateCCW;
34     int Drop;
35     int Pause;
36   };
37 
38   struct HighScore{
39     int Score;
40     std::string Scorer;
operator <Bastet::HighScore41     bool operator < (const HighScore &b) const{
42       return Score<b.Score;
43     }
operator ==Bastet::HighScore44     bool operator ==(const HighScore &b) const{
45       return (Score==b.Score) && (Scorer==b.Scorer);
46     }
47   };
48 
49   extern const size_t HowManyHighScores; //how many high scores to save in the file
50 
51   enum difficulty_t {difficulty_normal=0,difficulty_hard=1,num_difficulties=2};
52 
53   class HighScores: public std::vector<HighScore>{ //a set would not do the right job (think to ties)
54   public:
55     bool Qualifies(int score);
56     int InsertHighScore(int score, const std::string &scorer); //returns position (1 to HowManyHighScores), -1 if you don't make into the list
57   };
58 
59   extern const std::string RcFileName;
60   extern const std::string LocalHighScoresFileName;
61   extern const std::string GlobalHighScoresFileName;
62 
63   class Config{
64   private:
65     Keys _keys;
66     boost::array<HighScores,num_difficulties> _hs;
67   public:
68     Config();
69    ~Config();
70     Keys *GetKeys();
71     HighScores *GetHighScores(int difficulty);
72     std::string GetConfigFileName() const;
73     std::string GetHighScoresFileName() const;
74   };
75 
76   extern Config config; //singleton
77 }
78 
79 #endif //CONFIG_HPP
80