High Scores

[Home]   [Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

 

Available Now

Search

Google
 

Search WWW             

Search delphiforfun.org

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Help support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

Google
 

Search WWW

Search delphiforfun.org

 

 

 

Here is a TScores class that will keep track of name and score of the top scorers for your games. 

It works like this:

TScores is derived from TObjectList and maintains the specified number of high scorers in a list as TScoreObj objects.  Each TScoreObj contains a name and score.  The list is maintained in descending score sequence.  TScores has the following methods:

  • Procedure LoadScores(scoreFilename:string);  Initializes a TScores instance with previously saved top score information.    If  "scoreFilename"  file does not exist, an empty file is created. The file is  saved is an "Init" file format using TIniFile.   Note that by default TIniFile will look for and create files in the  Windows folder unless the filename includes path information.   In this test program, I create and maintain the file in the same foplder as the executable program. 
  • Procedure SaveScores(ScoreFileName:string);   Saves the current scores in the specified file.  
  • Function SetScore(newscore:integer; newname:string):integer;  Creates a TScoreObj object and inserts it in the appropriate place in the list (based on descending score information).  If the number of entries in the list after this insertion exceed the desired number of entries to keep, the final entry in the list is deleted. 
  • Procedure GetScores(list:TStrings);  Returns a displayable version of the information in TScores.
  • Function AddRec(rec:TScoreObj):integer;  Function used by Loadscores and SetScore to add objects to the list.  Probably not required for normal user use. 

The test program simply lets you add scores to a displayed list, clear the list, and change the number of of top scorers to remember.

I haven't really used the  code much so, as usual, let me know if you find a bug. 

Download source

 

Created: January 14, 2004

Modified: November 07, 2008

 

 


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2008, Gary Darby    All rights reserved.