#include <CHighScores.h>
Public Methods | |
| TInt | Number () |
| Number of entries in the table. More... | |
| void | AddScoreL (const TDesC &aName, TInt aScore) |
| Add a new high score. More... | |
| TBool | GoodEnough (TInt aScore) |
| Checks to see if a score qualifies for an entry. More... | |
| TInt | Score (TInt aEntry) |
| Return the score for an entry. More... | |
| const TDesC & | Name (TInt aEntry) |
| Return the name for an entry. More... | |
| TInt | LastAdded () |
| Last entry added. More... | |
| ~CHighScores () | |
| Destructor. More... | |
| void | InitL () |
| Create a blank high score table. More... | |
Static Public Methods | |
| CHighScores * | NewL (const TDesC &aFileName) |
| Leave safe construction. More... | |
Private Methods | |
| void | ConstructL (const TDesC &aFileName) |
| 2nd Phase construction. More... | |
| void | SaveL () |
| Save a high score table. More... | |
| void | LoadL () |
| Load a high score table. More... | |
| void | Reset () |
| Reset the high score arrays. More... | |
Private Attributes | |
| HBufC * | iFileName |
| file to store high score table in on exit. More... | |
| RArray< HBufC *> | iNames |
| Array of names. More... | |
| RArray< TInt > | iScores |
| Array of scores. More... | |
| TInt | iLastAdded |
| Last added, so that ui can highlite it. More... | |
Handles saving and restoring the high score table.
Definition at line 26 of file CHighScores.h.
|
|
Destructor. Tries to save the high scores back to the file Definition at line 133 of file CHighScores.cpp. References iFileName, iNames, and SaveL().
|
|
|
Leave safe construction.
Definition at line 94 of file CHighScores.cpp. References ConstructL(). Referenced by CGameState::ConstructL().
00094 {
00095 CHighScores* self= new (ELeave) CHighScores;
00096 CleanupStack::PushL(self);
00097 self->ConstructL(aFileName);
00098 CleanupStack::Pop(self);
00099 return(self);
00100 }
|
|
|
Number of entries in the table.
Definition at line 23 of file CHighScores.cpp. References KHighScoreEntries. Referenced by CGameAppView::DrawHighScores().
00023 {
00024 return KHighScoreEntries;
00025 }
|
|
||||||||||||
|
Add a new high score. Finds the correct position in the table. Removes the last entry in the table. Then adds the new one. Sets iLastAdded to the new entry so that the ui can highlite that line in the table.
Definition at line 40 of file CHighScores.cpp. References iLastAdded, iNames, iScores, and KHighScoreEntries. Referenced by CScoreDialog::OkToExitL().
00040 {
00041 for(TInt i=0;i<KHighScoreEntries;++i) {
00042 if(aScore > iScores[i]) {
00043 iNames.Remove(KHighScoreEntries-1);
00044 iScores.Remove(KHighScoreEntries-1);
00045
00046 HBufC* name=aName.AllocL();
00047 TInt error=iNames.Insert(name,i);
00048 if(error!=KErrNone) {
00049 delete name;
00050 User::Leave(error);
00051 }
00052 User::LeaveIfError(iScores.Insert(aScore,i));
00053 iLastAdded=i;
00054 return;
00055 }
00056 }
00057 }
|
|
|
Checks to see if a score qualifies for an entry. Resets the iLastAdded as a new game has been played Definition at line 64 of file CHighScores.cpp. References iLastAdded, iScores, and KHighScoreEntries. Referenced by CGameAppUi::HandleCommandL().
00064 {
00065 iLastAdded=-1;
00066 if(aScore > iScores[KHighScoreEntries-1])
00067 return ETrue;
00068 else
00069 return EFalse;
00070 }
|
|
|
Return the score for an entry.
Definition at line 77 of file CHighScores.cpp. References iScores. Referenced by CGameAppView::DrawHighScores().
00077 {
00078 return(iScores[aEntry]);
00079 }
|
|
|
Return the name for an entry.
Definition at line 86 of file CHighScores.cpp. References iNames. Referenced by CGameAppView::DrawHighScores().
00086 {
00087 return(*(iNames[aEntry]));
00088 }
|
|
|
Last entry added.
Definition at line 107 of file CHighScores.cpp. References iLastAdded. Referenced by CGameAppView::DrawHighScores().
00107 {
00108 return iLastAdded;
00109 }
|
|
|
Create a blank high score table.
Definition at line 159 of file CHighScores.cpp. References iNames, iScores, KHighScoreEntries, and Reset(). Referenced by ConstructL().
00159 {
00160 Reset();
00161 _LIT(KEmpty,"No One");
00162 TInt count=KHighScoreEntries;
00163 while(count--) {
00164 HBufC* name=KEmpty().AllocL();
00165 TInt error=iNames.Append(name);
00166 if(error!=KErrNone) {
00167 delete name;
00168 User::Leave(error);
00169 }
00170 User::LeaveIfError(iScores.Append(0));
00171 }
00172 }
|
|
|
2nd Phase construction. Load the high score table from the file, if that fails create a blank table. Definition at line 118 of file CHighScores.cpp. References iFileName, iLastAdded, InitL(), and LoadL(). Referenced by NewL().
00118 {
00119 iLastAdded=-1;
00120 iFileName=aFileName.AllocL();
00121 // try and load high scores, if that fails,
00122 // create empty high score sheet.
00123 TRAPD(error,LoadL());
00124 if(error!=KErrNone) {
00125 InitL();
00126 }
00127 }
|
|
|
Save a high score table.
Definition at line 177 of file CHighScores.cpp. References iFileName, iNames, iScores, and KHighScoreEntries. Referenced by ~CHighScores().
00177 {
00178 RFs fs;
00179 User::LeaveIfError(fs.Connect());
00180 CleanupClosePushL(fs);
00181
00182 RFileWriteStream file;
00183 User::LeaveIfError(file.Replace(fs,*iFileName,EFileWrite));
00184 CleanupClosePushL(file);
00185
00186 for(TInt i=0;i<KHighScoreEntries;++i) {
00187 file << *(iNames[i]);
00188 file.WriteInt32L(iScores[i]);
00189 }
00190
00191 CleanupStack::PopAndDestroy(2,&fs);
00192 }
|
|
|
Load a high score table.
Definition at line 197 of file CHighScores.cpp. References iFileName, iNames, iScores, and KHighScoreEntries. Referenced by ConstructL().
00197 {
00198 RFs fs;
00199 User::LeaveIfError(fs.Connect());
00200 CleanupClosePushL(fs);
00201
00202 RFileReadStream file;
00203 User::LeaveIfError(file.Open(fs,*iFileName,EFileRead));
00204 CleanupClosePushL(file);
00205
00206 for(TInt i=0;i<KHighScoreEntries;++i) {
00207 HBufC* name=HBufC::NewL(file,KMaxTInt);
00208 TInt error=iNames.Append(name);
00209 if(error!=KErrNone) {
00210 delete name;
00211 User::Leave(error);
00212 }
00213 TInt score=file.ReadInt32L();
00214 User::LeaveIfError(iScores.Append(score));
00215 }
00216
00217 CleanupStack::PopAndDestroy(2,&fs);
00218 }
|
|
|
Reset the high score arrays.
Definition at line 147 of file CHighScores.cpp. References iNames, and iScores. Referenced by InitL().
|
|
|
file to store high score table in on exit.
Definition at line 48 of file CHighScores.h. Referenced by ConstructL(), LoadL(), SaveL(), and ~CHighScores(). |
|
|
Array of names.
Definition at line 49 of file CHighScores.h. Referenced by AddScoreL(), InitL(), LoadL(), Name(), Reset(), SaveL(), and ~CHighScores(). |
|
|
Array of scores.
Definition at line 50 of file CHighScores.h. Referenced by AddScoreL(), GoodEnough(), InitL(), LoadL(), Reset(), SaveL(), and Score(). |
|
|
Last added, so that ui can highlite it.
Definition at line 51 of file CHighScores.h. Referenced by AddScoreL(), ConstructL(), GoodEnough(), and LastAdded(). |