1.1.0 • Published 6 years ago

mathgames-js v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

mathgames-js

MathGames API for Javascript

Install

NPM

npm install mathgames-js

CDN

The Math Games APi is also available from CDN.

javascript: https://cdn.mathgames.com/api/dist/latest/mathgames-api.js

css: https://cdn.mathgames.com/api/dist/latest/mathgames-api.css

Methods

MethodsParametersReturnsDescription
getInstance{ api_key: <string>, wrapper: <DOMElement>, debug: <boolean> }A new instance of the MathGames APIThe wrapper is a DOMElement which wraps the game canvas and is used to add api interface elements over the canvas.

Instance methods

MethodsParametersReturnsDescription
selectSkill{ pool_key: <string>}-Display the select skill dialog to the user. Requires a pool_key (generally 'COMPLETE').
startSession--Starts the session. StartSession should only be called after the SKILL_SELECTED event.
getQuestionsee question optionsQuestionObject see notes belowReturns a new question.
answerQuestionindex: number-The index parameter is the index of the question choice that was answered
showProgress--Display the progress dialog
showAvailableStandards--Display the progress dialog
endSession--Ends the session.

Events

EventReturnsDescription
SKILL_SELECTED-The user has selected a skill, startSession can be called
SESSION_READY-Session is ready. getQuestion can be called.
SKILL_CHANGED-The user has selected a different skill. This event will fire only if selectSkill is called during an active session.
PROGRESS_CLOSED-The user has closed the progress dialog
AVAILABLE_STANDARDS_CLOSED-The user has closed the available standards dialog
AVERAGE_TIME_CHANGEavgTime: numberThe average time has changed

Question Options

The getQuestion method accepts an object defining options to be used when rendering the question images.

The colors options acccept rgba colors in the form red, blue, green, alpha

Example:

{
    colors: {
        question: [12, 33, 169, 1], //blue
        choices: [
            [169, 12, 12, 1], //red
            [11, 21, 161, 1], //blue
            [23, 172, 63, 1], //green
            [216, 144, 0, 1] //orange
        ]
    }
}

Question Object

The question object has the image data needed to display the question using the following structure:

{
    display: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO8AAABlCAYAAAClW7QHAAASbElEQVR4Xu2de...",
    choices: [
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABDCAYAAAA735O5AAAF50lEQVR4Xu1b633bRgwHKM...",
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABDCAYAAAA735O5AAAFTklEQVR4Xu2b33nbNhDA7y...",
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABDCAYAAAA735O5AAAFDklEQVR4Xu2b0XnbOAzHAV..."
    ]
}

The display image is for the the display of the question and the choices image array are used for choice display. When the user selects a choice in game and the answerQuestion method is called, the index should match the index of the image in the choices array.

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.5

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago