1 /***************************************************************************
2                           hiscore.h  -  description
3                              -------------------
4     begin                : Wed Mar 1 2000
5     copyright            : (C) 2000 by Michael Speck
6     email                :
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef HISCORE_H
19 #define HISCORE_H
20 
21 /**
22   *@author Michael Speck
23   */
24 
25 struct HiScoreEntry {
26 	char	name[12];
27 	int		level;
28 	int     lives;
29 	int		score;
30 };
31 
32 
33 // HiScore is now an interface
34 class HiScore {
35  protected:
36   // You cannot directly create a HighScore object. Use
37   // CreateXXX instead.
HiScore()38   HiScore() {};
39 public:
40   // returns a pointer to a new high score table
41   // (the vanilla kind, only scores)
42   static HiScore* CreateStandard(char* fileName);
43   static HiScore* CreateComposite(char* fileName);
44   static HiScore* CreateLevel(char* fileName);
45 
46 	virtual ~HiScore();
47 	virtual int Load(char *f) = 0;
48 	virtual void Save(char *f) = 0;
49 	// saves back to the file it was loaded from
50 	virtual void Save() = 0;
GetTableCount()51 	virtual int GetTableCount() { return 1; };
52 	// table in [0..GetTableCount()-1]
53 	virtual HiScoreEntry Entry(int line, int table=0) = 0;
54 	virtual int CheckEntry(HiScoreEntry *entry) = 0;
55 };
56 
57 
58 // Standard, ordered by score
59 class StandardHiScore : public HiScore {
60  protected:
61 	HiScoreEntry	*entries;
62 	int				entry_num;
63 	char			filename[1024];
64  public:
65   StandardHiScore(char* f);
66   StandardHiScore(FILE* f);
67   virtual ~StandardHiScore();
68 	virtual void Create();
69 	virtual int Load(char *f);
70 	virtual void Save(char *f);
71 	// saves back to the file it was loaded from
72 	virtual void Save();
73 	virtual HiScoreEntry Entry(int line, int table=0);
74 	virtual int CheckEntry(HiScoreEntry *entry) ;
75 
76 	virtual int Load(FILE* file);
77 	virtual void Save(FILE* file);
78 };
79 
80 // this time we order by level
81 class LevelHiScore: public StandardHiScore {
82  public:
LevelHiScore(char * f)83   LevelHiScore(char* f) : StandardHiScore(f) {};
LevelHiScore(FILE * f)84   LevelHiScore(FILE* f) : StandardHiScore(f) {};
85   virtual int CheckEntry(HiScoreEntry *entry);
86 };
87 
88 // maintains two tables: one per score, the other per level
89 class CompositeHiScore : public HiScore {
90  private:
91    char filename[1024];
92    LevelHiScore* pLevel;
93    StandardHiScore* pStandard;
94 
95  public:
96    CompositeHiScore(char* f);
97    virtual ~CompositeHiScore();
98 
99    virtual HiScoreEntry Entry(int line, int table=0);
100    virtual int CheckEntry(HiScoreEntry *entry) ;
101    virtual void Save();
102 
103    virtual int Load(char *f);
104    virtual void Save(char *f);
105 };
106 
107 #endif
108