1 #pragma once
2 // Description:
3 //   Score keeper.
4 //
5 // Copyright (C) 2001 Frank Becker
6 //
7 // This program is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free Software
9 // Foundation;  either version 2 of the License,  or (at your option) any  later
10 // version.
11 //
12 // This program is distributed in the hope that it will be useful,  but  WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
15 //
16 
17 #include <string>
18 #include <vector>
19 
20 #include <time.h>
21 
22 #include "Point.hpp"
23 #include "Singleton.hpp"
24 
25 using namespace std;
26 
27 struct ScoreData
28 {
29     int score;
30     string name;
31     time_t time;
32     int goodiesCaught;
33     int goodiesMissed;
34     int skill;
35 };
36 
operator <(const ScoreData & s1,const ScoreData & s2)37 inline bool operator< (const ScoreData &s1, const ScoreData &s2)
38 {
39     // ">" since we want highscore first
40     return s1.score > s2.score;
41 }
42 
43 class ScoreKeeper
44 {
45 friend class Singleton<ScoreKeeper>;
46 public:
47     ~ScoreKeeper();
48     ScoreKeeper( void);
49 
getCurrentScore(void)50     int getCurrentScore( void)
51     {
52 	return _leaderBoard[_currentIndex].score;
53     }
54 
55     void resetCurrentScore( void);
56 
57     int addToCurrentScore( int value);
58 
59     void incGoodiesCaught( void);
60     void incGoodiesMissed( void);
61 
62     int goodiesCaught(void);
63 
getScore(unsigned int index)64     int getScore( unsigned int index)
65     {
66 	if( index < _leaderBoard.size())
67 	{
68 	    return _leaderBoard[ index].score;
69 	}
70 
71 	return 0;
72     }
73 
74     const string getInfoText( unsigned int index);
75 
getHighScore(void)76     int getHighScore( void)
77     {
78 	return _leaderBoard[0].score;
79     }
80 
boardSize(void)81     int boardSize( void)
82     {
83 	return (int)_leaderBoard.size();
84     }
85 
currentIsTopTen(void)86     bool currentIsTopTen( void)
87     {
88 	return  _currentIndex < 10;
89     }
90 
setName(const string & name)91     void setName( const string &name)
92     {
93 	_leaderBoard[_currentIndex].name = name;
94     }
95 
96     void load( void);
97     void save( void);
98     void draw( const Point2Di &offset);
99 
100 private:
101     ScoreKeeper( const ScoreKeeper&);
102     ScoreKeeper &operator=(const ScoreKeeper&);
103 
104     void updateLeaderBoard( void);
105     void dump( void);
106 
107     unsigned int _currentIndex;
108     vector<ScoreData> _leaderBoard;
109 };
110 
111 typedef Singleton<ScoreKeeper> ScoreKeeperS;
112