kele6ra / 2048

npm version of 2048, custom it yourself

Home Page:https://ppq1991.github.io/2048/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2048

Just change the origin code to CommonJS version and publish it to npm to make it easy to use.

Demo

https://ppq1991.github.io/2048/

Usage

import
npm i -S game-2048
html
<div id="container"></div>
javascript
import 'game-2048/style/main.css';
import Game from 'game-2048';
const game = new Game({
  gameContainer: document.getElementById('container')
}); 

Config

constructor
property type desc required default
gameContainer HTMLElement the game container undefined
startTiles number number of tiles in the game beginning X 2
endScore number the score to win the game X 2048
keepPlaying boolean show keep playing button after player reach the end score X false
title string title X 2048
desc string brief intro X Join the numbers and get to the 2048 tile!
playerWinMessage string alert message content when game won X You Win!
playerLoseMessage string alert message content when game over X Game Over!
retryButtonText string retry button text X Try Again
keepPlayingButtonText string keep playing button text X Keep Going!
newGameButtonText string button text X New Game
initValue number init value of the first tile X 2
getNextValue function call this function to get next value X v => v * 2
getClassNameByValue function call this function to get classname X v => tile-${v}
onGameStart function on game start hook X undefined
onGameOver function onGameOver(score, isWin) X undefined
methods

Screenshot

Screenshot

License

2048 is licensed under the MIT license.

About

npm version of 2048, custom it yourself

https://ppq1991.github.io/2048/

License:MIT License


Languages

Language:JavaScript 53.9%Language:CSS 43.1%Language:HTML 3.0%