@marcelotivelabs/memory
v0.2.15
Published
memory game library
Downloads
9
Readme
memory-game
installing library
- To install memory-game library in your project just run the following command:
npm i @tive-labs/memory-game
Using memory-game library
Import the library
- At the beginning of the js file in which you are going to use the library import as follows:
import {initGame, selectCard} from @tive-labs/memory-game
initGame
- initGame receives two parameters, category and level.
- Category must be 'animals' or 'numbers'
- Level must be 'easy' or 'medium' or 'hard'
const memoryGame = initGame('animals', 'easy');
- initGame returns an object with a 2d array of hidden cards, and the length of the array (xLength and yLength):
{
cards,
xLength,
yLength
}
selectCard
selectCard receives two parameters, position x and position y.
- x must be a number representing the x position (vertival position) on the 2d array.
- y must be a number representing the y position (horizontal position) on the 2d array.
const selected = selectCard(0, 1);
selectCard returns an object with three properties:
{ cardData, cardMatch, isThereAWinner }
- cardData: Contains an object with the data of the discovered card (id, name, shortName)
- cardMatch: Contains an object with a boolean value (isNewMatched) that indicates if exist a new card match, and an object (matchedCards) with the positions of the matched cards (x_y):
{ isNewMatched, matchedCards: { firstCard, lastCard } }
- isThereAWinner: Contains a boolean value indicating if the player won the game.