//_______________________________"StringLibrary.agc" ________________________(put this as separate file , and name it "StringLibrary.agc")......... // This is an 'include file'____________________It contains 2 functions that you will call from your 'main' file. //*************************************** //*** Functions *** //*************************************** // FUNCTION //*** Updates high score list in file and returns updated list *** function UpdateHighScoresFile(player as PlayerType) gamesplayed as PlayerType[5] //Contains high score details //*** If high scores file exists *** if GetFileExists("HighScores.dat") = 1 //*** Open file for reading *** fileID = OpenToRead("HighScores.dat") //*** Read the file’s details *** for c = 1 to 5 gamesplayed[c].name = ReadString(fileID) gamesplayed[c].score = ReadInteger(fileID) next c //*** Close the file *** CloseFile(fileID) endif //---------------------------------------------------------------------- //*** If current game is added to high score list... *** if UpdateTopScoresList(gamesplayed,player) = 1 //*** Open high score file for writing *** fileID = OpenToWrite("HighScores.dat") //*** Write updated list to file *** for c = 1 to 5 WriteString(fileID, gamesplayed[c].name) WriteInteger(fileID, gamesplayed[c].score) next c CloseFile(fileID) endif endfunction gamesplayed // FUNCTION //*** Adds newscore to list, if newscore contains a high score *** //*** Returns 1 if added, 0 if not added *** function UpdateTopScoresList(list ref as PlayerType[], newscore as PlayerType) //*** Find insert point *** post = 1 while post < list.length and list[post].score > newscore.score inc post endwhile //*** If not a high score, return zero *** if list[post].score > newscore.score exitfunction 0 endif //*** Free up cell *** for c = list.length-1 to post step -1 list[c+1] = list[c] next c //*** Insert value *** list[post] = newscore //*** Value added to list, return 1 *** endfunction 1 //*************************************** //*** Functions *** //*************************************** //*** Generates a random-length string of random letters *** function RandomString() //*** Generate length for string *** size = Random(1,50) //*** start with empty string *** result as string = "" //*** FOR size times *** for c = 1 to size //*** Add new character to end of string *** result = result + Chr(Random(65,90)) next c //*** return the string generated *** endfunction result