1.4.5 • Published 4 years ago
2048-ts-engine v1.4.5
Getting Started 🚀
2048-ts-engine handles logic for 2048 game. Despite being written in Typescript, you can also use plain JS, if TS is not needed.
Installation
yarn add 2048-ts-engineHow to use
- The lib returns two main functions
startGame- simply starting the gamemove- evaluating move, calculating points, board coordination etc,
- accepts these parameters
direction: Direction game: Game
Both these functions return all game related data (board coordinates, score, status etc.) which look like this:
{
"score": 16,
"board": [
[ 0, 0, 4, 0 ],
[ 0, 0, 0, 0 ],
[ 2, 0, 0, 0 ],
[ 4, 8, 0, 8 ]
],
"gameStatus": "STARTED"
}You will need to store the current state somewhere, since the engine only processes the game, and after every move, the current state of game is returned.
import { startGame, move } from '2048-ts-engine';
import { Direction, Game, GameStatus } from '2048-ts-engine/src/types';
const newGame = startGame();
const gameProcessed = move(Direction.UP, newGame);Useful scripts
# test game logic
yarn test1.4.5
4 years ago
1.4.4
4 years ago
1.2.6
4 years ago
1.4.3
4 years ago
1.4.2
4 years ago
1.4.1
4 years ago
1.3.2
4 years ago
1.4.0
4 years ago
1.3.1
4 years ago
1.3.0
4 years ago
1.1.1
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.0
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago