jq-memory-game
Simple memory game with cards
Based on @Jonathan Tarnate
Modifications over the original code:
- Adapted to jquery widget
- Count number of interactions
- Events
- Render by json data
Dependencies
- jquery
- jQuery UI:
- jQuery UI widget
Features
- Options to configure the behavior
- Specify items by json data
- Shuffle cards
- Count the number of interactions
- Event to notify each interaction
- Event to notify completion
Playground
Usage
Install with npm i jq-memory-game
Vanilla ES2015
;//choose one of the follow options//for jquery-ui package;//for jquery-ui-dist package;; const $el = ;$el;$el;$el;$el;$el
Please note that depending of the bundler you are using other configurations may be necessary. For example, shimming JQuery and jQuery UI.
jQuery UI
jQuery UI could be included in the projects in many different ways and with different packages, instead of force you to use one, we leave up to you how to include it:
Modularized
Using npm i jquery-ui
that install the package allowing to import the widgets you want.
We provided a file with the imports of the required dependencies:
;
Options
Events
Event name | Detail | Emit |
---|---|---|
memoryGameStart | Triggered when the game starts or is reset | |
memoryGameCardFlipped | Triggered every time a single card is flipped | The card flipped |
memoryGameCardsCheck | Triggered after check if the two cards flipped match | boolean indicating if the cards match, the number of interactions performed by the player, an array with the two cards flipped |
memoryGameComplete | Triggered when the game is completed |
Methods
Available methods to invoke:
Method | Short description |
---|---|
destroy | Destroy the widget |
disable | Disable the widget |
enable | Enable the widget |
flip | Flip a card by index |
reset | Reset the game |