0.1.4 ā€¢ Published 7 years ago

wasd-tetris v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Description

šŸŽ® A tetris only with core data layer.

Table of contents

Features

  • No dependences.
  • Only provide data operation.
  • Custom UI.

Installation

yarn add wasd-tetris

Demo

Usage

import Tetris from 'wasd-tetris'

const tetris = new Tetris()

tetris.on('repaint', graph => {
  // draw graph
})

tetris.start()

API

Tetris

Options

NameDescriptionTypeAccepted ValuesDefault
matrixMatrix for tetrisMatrix-matrix
autoWhether auto progress gameBoolean-true
speedThe speed (milliseconds) of falling blockNumber-500

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
graph(getter)The graph of current game-ā€”ā€”

Events

Event NameDescriptionParameters
repainttriggers when game need reapintgraph
hittriggers when block hit existed block or bottom of the matrix-
overflow:lefttriggers when block hit left of the matrix-
overflow:righttriggers when block hit right of the matrix-
hit:rotatetriggers if block hit after rotate-
clear:linestriggers when lines need to be cleardlines
failedtriggers when game over-

Methods

MethodDescriptionParameters
startstart the game-
resetreset the game-
pausepause the game-
resumeresume the game-
failfail the game-
savesave current state of the game-
restorerestore the last saved state-
addBlockadd new blockblock
dropmove the block down until hit-
downmove the block down-
leftmove the block left-
rightmove the block right-
rotaterotate the block-

Block

Options

NameDescriptionTypeAccepted ValuesDefault
xX coordinateNumber-0
yY coordinateNumber-0
shapeShape of the blockshape-random shape

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
coordinate(getter)The coordinate of current gameObjectā€”{ x, y, array }

Methods

MethodDescriptionParameters
moveBymove the block to a relative positionx, y
moveTomove the block to a absolute positionx, y
rotaterotate the block clockwise or anti-clockwiseclockwise

Shape

Options

NameDescriptionTypeAccepted ValuesDefault
shapeInitial shape of the ShapeArray-[]

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
shape(getter)Current shapeArrayā€”-
index(getter)Current indexNumberā€”0
index(setter)Set current indexNumberā€”-
margin(getter)Margin of current shapeObject-{ row, col, top, left, bottom, right }

Methods

MethodDescriptionParameters
cloneclone Shape-
rotaterotate current shape clockwise or anti-clockwiseclockwise

Matrix

Options

NameDescriptionTypeAccepted ValuesDefault
rowrow of the matrixNumber-20
colcolumn of the matrixNumber-10
xX coordinateNumber-0
yY coordinateNumber-0

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
coordinate(getter)The coordinate of matrixObjectā€”{ x, y, array }

Methods

MethodDescriptionParameters
resetreset matrix to initial state-

Development

yarn
yarn dev

License

MIT

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago