This is a simple game template that connects to a SCORM server. It is aimed at developing games consisting of a number of rounds, each using a common layout but using different data. It's really easy to adapt.
The diagram below indicated the flow of the game screens.
┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━━┓ ┏━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━┓
┃ STARTGAME ┃--->┃ STARTROUND ┃--->┃ GAME ┃--->┃ ENDROUND ┃--->┃ ENDGAME ┃
┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━━┛ ┗━━━━━━┛ ┗━━━━━━━━━━┛ ┗━━━━━━━━━┛
^ ┇
╰────────────────────────────╯
There are four functions provided for you to add your game functionality:
launch()
– runs once on page load (before the STARTGAME screen is displayed).startRound(roundName)
– runs at the start of each round (before the STARTROUND screen is displayed). The name of the round is passed as a parameter.endRound(roundName)
– runs at the end of the round just before the ENDROUND screen is displayed. The name of the round is passed as a parameter.endGame(scores)
– runs once, just before the ENDGAME screen is displayed. Thescores
parameter contains an array of the scores for each round.
Each screen of the game is defined as a main
element and all but one are set to hidden. The showSection()
function takes the id
of the section to display, shows this and hides the rest. If there is a button to take the user to the next screen this will have a class of next
.
Each main element can contain multiple section
elements to manage the layout and visibility. There are a couple of pre-defined ones:
tooltip
displays information that appears and then remains visible and is triggered using theshowTooltip()
function that takes two parameters, the title and message.notification
displays a simple message for a defined length of time in seconds and them disappears. It is called using theshowNotification()
function and takes two parameters, the message string and an optional duration in seconds (defaults to 3 seconds).
The data.json
file defines the rounds of the game. Edit the rounds
array. The name
property defines the URL hash string that will load the round. The rest of the objects define information to be displayed in each round. You can add as many properties as you wish. To insert the values into the html, assign a class that matches the appropriate object key, for example to display the title
value in a top-level heading, add the following:
<h1 class="title></h1>
Hidden Elements
Certain elements such as tooltips and notifications should be hidden at the start of every round. To achieve this give them the hide
class.
The common.js
script is imported into the project and provides the following functions:
loadData(filename)
– loads the script with the name matching the parameter. It looks for JSON-formatted files in thedata/
directory only and the filename should not include the.json
file extension. It returns a JavaScript object.showSection(name)
– hides all themain
elements except the one with an id attribute matching the parameter.addScore(score)
– appends the score specified in the parameter to an array of scores that will be passed to theendGame()
function.showNotification(message, delay = 3)
– displays the test string in themessage
parameter for 3 seconds (can be changed by supplying a second numerical parameter).
The following SCORM functions are already implemented in the scripts, they are listed below for reference:
startGame()
– this is called at the start of the game. It changes the completion status fromnot attempted
toincomplete
and sets the max score based on either one provided by the LMS or 100 by default. It also captures the current date and time to allow the game to calculate how long a user spend in the game.updateScore(score)
– saves the score supplied as the parameter to the SCORM server if it is numerical and in a valid range.finishGame(score)
– called right at the end of the game. It saves the score passed as a parameter and then updates the status, topass/fail
if a mastery score is provided in the LMS but if not tocompleted
. Finally it calculates how long the user was in the game. The status and session time data is pushed back to the LMS.