Skip to content

misaka42/2048

 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 54.1%
  • CSS 42.8%
  • HTML 3.1%