0% found this document useful (0 votes)
2 views

High Score Object

This document describes a script for creating a high score tracking object in a game. It outlines how to initialize the object with parameters such as the number of entries, player name, and default score, as well as how to add and retrieve high scores. The script includes public and private functions for managing the high score list and determining the highest and lowest scores.

Uploaded by

Josh Chunick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

High Score Object

This document describes a script for creating a high score tracking object in a game. It outlines how to initialize the object with parameters such as the number of entries, player name, and default score, as well as how to add and retrieve high scores. The script includes public and private functions for managing the high score list and determining the highest and lowest scores.

Uploaded by

Josh Chunick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-- High Score Object - highscore object

-------------------------------------------------------
-- ©2007 Josh Chunick
--
-- This parent script creates an object that can be
-- used to keep track of the high scores section in
-- a game.
--
-- To intitialize the object:
-- highScoreObj = script("highscore object").new(10, "AAA", 10000)
-- the first parameter is the number of entries in the highScore list
-- the second parameter is the name of the player - in this case, the default
-- using old style 3 letter arcade convention.
-- the third parameter is the default score that will be shown; arcade convention.
-- Passing the initial parameters are optional. The default values are 10, "AAA", 0

-- ***********
-- if you want to add other parameters then this format will work:
-- [[ #score: 3200, #player:"John", #time: the systemDate]]
-- in this format the sub-property list will be sorted using sort() property
-- based on the first property:item entry in the list.
-- ***********
various initParams configurations
-- [#loadMethod: {#getPref, #fileIO, #xtra}, #prefName: "", #filePath: {"C:\..\..",
http://../}, #handlerName: "someHandler"]
-- ie. [#loadMethod: #getPref, #prefName: "somePrefName"]
-- ie. [#loadMethod: #fileIO, #filePath: "C:\Documents and
Settings\<user>\Applications\<game>\highscore.txt"]
-- ie. [#loadMethod: #xtra, #handlerName: "someHandler"]

property pHighScoreList

-------------------------------------------------------
---------------- PUBLIC FUNCTIONS ---------------------
-------------------------------------------------------

on new me, initParams


initList = []
-- if initParams is a list then check to see if it's
-- a property list.
if listP(initParams) and ilk(initParams) = #propList then
-- if it's a propList then check to see if it's been set up
-- to get the prefs file or read a file in or configure for first-time...

end if
end if

if voidP(initParams) or initList.count = 0 then


-- nothing has been set... set up default parameters
initList = [ #score: 10000, #player:"AAA", #team: "", #rank: 0, #date: the systemDate]
me.initializeHighScore(maxEntries, initName, initScore, initDate)
end if

return me
end

on initializeHighScore me, mEntries, iName, iScore, iDate


if not(integerP(mEntries)) then mEntries = 10
if not(stringP(iName)) then iName = "AAA"
if not(integerP(iScore)) then iScore = 0
if ilk(iDate) <> #date then iDate = the systemDate
pHighScoreList = []
pHighScoreList.sort()
playerList = [:]
playerList.addProp(#score, iScore)
playerList.addProp(#player, iName)
playerList.addProp(#date, iDate)
repeat with i = 1 to mEntries
pHighScoreList.add(playerList)
end repeat
return true
end

on getHighScores me, order


if order = #desc then
reverseList = []
hsCount = pHighScoreList.count
repeat with i = hsCount down to 1
reverseList.add(pHighScoreList[i])
end repeat
return reverseList
end if
return pHighScoreList.duplicate()
end

on addHighScore me, playerName, playerScore


if not(stringP(playerName)) then return false
if not(integerP(playerScore)) then return false
put me.determineHighScore(playerScore)
if me.determineHighScore(playerScore) then
playerList = [:]
playerList.addProp(#score, playerScore)
playerList.addProp(#player, playerName)
playerList.addProp(#date, the systemDate)
pHighScoreList.add(playerList)
pHighScoreList.deleteAt(1)
return true
end if
return false
end

on determineHighScore me, theScore


if theScore > pHighScoreList[1][1] then return true
return false
end

on getNumberOfHighScores me
return pHighScoreList.count
end

on getHighestScore me
return pHighScoreList.max()
end

on getLowestScore me
return pHighScoreList.min()
end

-------------------------------------------------------
---------------- PRIVATE FUNCTIONS --------------------
-------------------------------------------------------
on leftPadZero me, str, pad
repeat while length(str) < pad
str = "0" & str
end repeat
return str
end

You might also like