1.4.5 • Published 2 years ago

2048-ts-engine v1.4.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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-engine

How to use

  • The lib returns two main functions
    • startGame - simply starting the game
    • move
      • 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 test
1.4.5

2 years ago

1.4.4

2 years ago

1.2.6

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.1

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago