
-----------------------------------
Aziz
Thu Jun 09, 2005 7:26 am

Highscore Library
-----------------------------------
If that's what you'll call it? Anyways I've come up with a nifty module for using Highscores (any amount of names, scores, as well as using multiple files)

I've attached the .tu file.

Here's the syntax:

fcn Size (fileName : string) : int
Returns the size (how many scores & names) of the file fileName.

ex. a file like this:

Aziz$200#
Marcus$75#
Joel$30#

has a size of 3

proc CreateFile (size : int, fileName : string)
Creates a highscore file of size size with the file name fileName.
All names will be defaulted to "---" and score will be defaulted to 0.

proc ClearScores (fileName : string)
Resets all the names in the file to "---" and scores to 0.

proc GetScores (var names : array 1 .. * of string, var scores : array 1 .. * of int, fileName : string)
Stores all the names and scores of the highscore file fileName into the names and scores parameters.

proc AddScore (userName : string, userScore : int, fileName : string)
Add a name and score to the highscore file fileName.

fcn TopName (fileName : string) : string
Returns the name of the top score holder.

fcn TopScore (fileName : string) : int
Returns the score of the top score holder.

Also, here's a test program to try it out:

import "Highscore.tu"

var fileName, choice : string
var size : int

loop
    cls

    put "Highscore file name [type ESC to exit]: " ..
    get fileName : *
    exit when Str.Upper (fileName) = "ESC"

    if File.Exists (fileName) then
        put "File Found."
    else
        put "File Not Found, define size of new file?", skip, "If no, default size to 10 scores [Y/N] " ..
        loop
            get choice : *
            choice := Str.Upper (choice)
            exit when choice = "Y" or choice = "N"
            locate (whatrow - 1, 40)
        end loop
        if choice = "Y" then
            put "# Of Highscores to be stored: " ..
            get size
            put "Number of highscores in ", fileName, " set to ", size, "."
        else
            put "Number of highscores in ", fileName, " defaulted to 10."
            size := 10
        end if
        Highscore.CreateFile (size, fileName)
        put "File ", fileName, " created."
    end if

    put skip, "Any key to continue"
    Input.Pause

    loop
        var choice2, score : int
        var name : string
        var names : array 1 .. Highscore.Size (fileName) of string
        var scores : array 1 .. Highscore.Size (fileName) of int
        cls
        put "Commands for highscore list ", fileName, ":"
        put "1: Get List Size"
        put "2: Clear the scores"
        put "3: Display list of Highscores"
        put "4: Check the top place holder"
        put "5: Add a score"
        put "6: Delete file"
        put "7: Exit"
        loop
            get choice2
            exit when choice2 >= 1 and choice2 