game-2048
v0.0.7
Published
A small clone of [1024](https://play.google.com/store/apps/details?id=com.veewo.a1024), based on [Saming's 2048](http://saming.fr/p/2048/) (also a clone).
Downloads
417
Readme
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
License
2048 is licensed under the MIT license.