WordFind: Creating a High-Score table

WordFind can pass back information about the completed puzzle, such as the time taken to complete the puzzle and how many mistakes were made.

You can use this information to simply tell the user how they did, or go a step further and record the information in a high-score table.

The information is passed back in POST variables, and you can use it with whatever type of server-side scripting you are familiar with (e.g. PHP).

Included sample script

The sample script provided with WordFind, "score.php", simply lists the variables and their values.  E.g.

NameDescriptionValue
puz This is the id as defined in your puzzle definition file. Puzzle1
mistakes How many mistakes were made. 1
timesecs The time it took to complete in seconds (useful for calculations). 21.17
time The time it took to complete, as a readable string. 21 seconds

Creating your own High Score script

You can use the fields in whatever way you like, but as a basic guide your script should do the following...

  1. Calculate a score, based on the variables received.
    You can base your score on the time alone, or penalise for the number of mistakes.
  2. Show the user their score (and perhaps where they rank), and provide a form where they can enter their name.
  3. Have a button that posts the score back to the server.
    You will also need to include any other variables, such as your calculated score, in hidden form variables.
  4. In the second script process the variables to save the score in some way and show a high-score table.

High Score script used by Kea Software

You can find sample WordFind puzzles on our main website.

The site uses Joomla, with the script embedded into the page.  You can download the script here...
http://www.keasoftware.com/download/wordfind/wordfind_scoring_sample.zip

As well as handling scoring this script also shows the list of puzzles for selection, and then shows the selected puzzle.  The script is well documented, and some of the most important parts are further detailed below.

For scoring the script just uses the time.  The shorter the time is the higher it ranks.

The MAIN part of script

If we have the request variable "puz" then we are either showing the puzzle or doing scoring.

If we have the variable "mistakes" then it must be score related so we call doScoring().

Otherwise we should just display the puzzle, using showGame().

If we don't have "puz" then we should be showing the list - call showGames().

doScoring()

We load the scores, by calling loadscores().

If we have "name" then this is a new high score...

Get the details, calculate the new score, insert it into the current scores, and then save.

Show the current high-score table.

If we don't have "name"...

Show the current scores.

Determine of the new score makes the high-score table.  If it does show a form allowing them to post their score.

Show a list of games to choose from.

Loading and Saving scores

The scores are saved in a CSV file with the same base name as the puzzle.

Each line is just the name followed by the time.  A constant "MAXSCORES" is used to limit the number of scores saved.