2.0.4 • Published 3 years ago

tetris-ts v2.0.4

Weekly downloads
11
License
MIT
Repository
github
Last release
3 years ago

tetris-ts

npm version code style: prettier MIT Licence

A simple Tetris clone written in plain Typescript.

npm.io

Installation

Yarn

yarn add tetris-ts

NPM

npm install tetris-ts --save

Usage

// ES6 Import
import Tetris from 'tetris-ts';

// CommonJS Require
const Tetris = require('tetris-ts').default;

The library takes 3 parameters in the constructor

  • DOM Element to attach to
  • Callback function invoked when a game finishes
  • Options object (optional) for customizations

Important: The width of the DOM element determines the size of the game.

<div id="tetris" style="width: 275px;">
const el = document.getElementById('tetris');

const callback = function (data) {
    // Do something with the data returned from the game
};

const tetris = new Tetris(el, callback, {
    frameConstant: 60,
    linesPerLevel: 10,
});

The Options object has the following properties:

PropertyDescriptionDefault
frameConstantControls the speed of the game60.8
linesPerLevelCompleted lines needed to advance the level10

Data is returned as an object with the following properties:

PropertyData TypeDescription
pointsNumberTotal points earned
linesNumberTotal lines cleared
levelNumberHighest level achieved

About

I had two primary goals when writing this library. The first was to learn Typescript. Tutorials are great, but I wanted to go through the process of what its really like to develop a project in the language - the syntax, the semantics, and the tooling. The second goal was to write without using any dependencies in the code itself. No lodash, no jQuery; just pure Typescript.

That being said - this is by no means a 100% accurate clone of Tetris. I kept as much of the essence of the game as I could without making the project overly complicated.

This will be my first project in Typescript, as well as my first package published to NPM, so by all means, r/RoastMe.

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago