Game Development Reference
In-Depth Information
String Initials = "AAA";
int Score = 0;
// Initialize High Score Entries
for (int i = 0; i < MAX_SCORES; i++)
{
m_HighScoreTable[i] = new HighScoreEntry(Initials,Score);
m_HighScoreTable[i].SetItemValidState(false);
}
m_Text = CharacterSet;
m_FontWidth = m_Text.GetFontWidth();
m_FontHeight = m_Text.GetFontHeight();
m_HighScoreTableImage = HighScoreTableImage;
// Load In Saved high Scores
LoadHighScoreTable(HIGH_SCORES);
m_Dirty = true;
}
The SaveHighScoreTable() function saves the player's top MAX_RANK number high score entries
consisting of the player's initials and the player's score. (See Listing 9-12.)
Listing 9-12. Saving the High Score Table
void SaveHighScoreTable(String Handle)
{
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
SharedPreferences.Editor editor = settings.edit();
for (int i = 0; i < MAX_RANK; i++)
{
editor.putString("Name" + i, m_HighScoreTable[i].GetInitials());
editor.putInt("Score" + i, m_HighScoreTable[i].GetScore());
}
// Commit the edits!
editor.commit();
}
The LoadHighScoreTable() function loads the player's high score data consisting of the player's
name or initials and the player's score. If the player's score is greater than 0, the entry is valid.
(See Listing 9-13.)
Listing 9-13. Loading the High Score Table
void LoadHighScoreTable(String Handle)
{
// Restore preferences
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
 
Search WWH ::




Custom Search