Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Highscore Library
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aziz




PostPosted: Thu Jun 09, 2005 7:26 am   Post subject: 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:

code:
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 <= 7
            locate (whatrow - 1, 1)
        end loop
        cls
        if choice2 = 1 then
            put "The highscore list holds ", Highscore.Size (fileName), " scores."
        elsif choice2 = 2 then
            Highscore.ClearScores (fileName)
            put "Scores Cleare :)"
        elsif choice2 = 3 then
            Highscore.GetScores (names, scores, fileName)
            put "Name" : 10, "Score" : 5
            for i : 1 .. Highscore.Size (fileName)
                put names (i) : 10, scores (i) : 5
            end for
        elsif choice2 = 4 then
            put "The top score holder is ", Highscore.TopName (fileName), " with a score of ", Highscore.TopScore (fileName), "."
        elsif choice2 = 5 then
            put "Name: " ..
            get name : *
            put "Score: " ..
            get score
            Highscore.AddScore (name, score, fileName)
            put "Score added."
        elsif choice2 = 6 then
            File.Delete (fileName)
            put "File deleted. Any key to return to finish."
            Input.Pause
            exit
        else
            exit
        end if
        put skip, "Any key to continue." ..
        Input.Pause
    end loop
end loop
Window.Hide (defWinID)


You can use this by putting "import "Highscore.tu"" in your file.
All procedures and function are export qualified. File is attached Smile



Highscore.tu
 Description:
Highscores wee

Download
 Filename:  Highscore.tu
 Filesize:  3.75 KB
 Downloaded:  211 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
decon1985




PostPosted: Thu Jun 09, 2005 12:51 pm   Post subject: AWSOMENESS!

This is really useful! Man, i wouldn't change a thing!
dann_west




PostPosted: Fri Jun 10, 2005 2:25 pm   Post subject: Re: Highscore Library

nice!

From D
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: