๐ฎ A tetris only with core data layer.
- No dependences.
- Only provide data operation.
- Custom UI.
import Tetris from 'wasd-tetris'
const tetris = new Tetris()
tetris.on('repaint', graph => {
// draw graph
})
tetris.start()
| Name |
Description |
Type |
Accepted Values |
Default |
| matrix |
Matrix for tetris |
Matrix |
- |
matrix |
| auto |
Whether auto progress game |
Boolean |
- |
true |
| speed |
The speed (milliseconds) of falling block |
Number |
- |
500 |
| Attribute |
Description |
Type |
Accepted Values |
Default |
| graph(getter) |
The graph of current game |
- |
โ |
โ |
| Event Name |
Description |
Parameters |
| repaint |
triggers when game need reapint |
graph |
| hit |
triggers when block hit existed block or bottom of the matrix |
- |
| overflow:left |
triggers when block hit left of the matrix |
- |
| overflow:right |
triggers when block hit right of the matrix |
- |
| hit:rotate |
triggers if block hit after rotate |
- |
| clear:lines |
triggers when lines need to be cleard |
lines |
| failed |
triggers when game over |
- |
| Method |
Description |
Parameters |
| start |
start the game |
- |
| reset |
reset the game |
- |
| pause |
pause the game |
- |
| resume |
resume the game |
- |
| fail |
fail the game |
- |
| save |
save current state of the game |
- |
| restore |
restore the last saved state |
- |
| addBlock |
add new block |
block |
| drop |
move the block down until hit |
- |
| down |
move the block down |
- |
| left |
move the block left |
- |
| right |
move the block right |
- |
| rotate |
rotate the block |
- |
| Name |
Description |
Type |
Accepted Values |
Default |
| x |
X coordinate |
Number |
- |
0 |
| y |
Y coordinate |
Number |
- |
0 |
| shape |
Shape of the block |
shape |
- |
random shape |
| Attribute |
Description |
Type |
Accepted Values |
Default |
| coordinate(getter) |
The coordinate of current game |
Object |
โ |
{ x, y, array } |
| Method |
Description |
Parameters |
| moveBy |
move the block to a relative position |
x, y |
| moveTo |
move the block to a absolute position |
x, y |
| rotate |
rotate the block clockwise or anti-clockwise |
clockwise |
| Name |
Description |
Type |
Accepted Values |
Default |
| shape |
Initial shape of the Shape |
Array |
- |
[] |
| Attribute |
Description |
Type |
Accepted Values |
Default |
| shape(getter) |
Current shape |
Array |
โ |
- |
| index(getter) |
Current index |
Number |
โ |
0 |
| index(setter) |
Set current index |
Number |
โ |
- |
| margin(getter) |
Margin of current shape |
Object |
- |
{ row, col, top, left, bottom, right } |
| Method |
Description |
Parameters |
| clone |
clone Shape |
- |
| rotate |
rotate current shape clockwise or anti-clockwise |
clockwise |
| Name |
Description |
Type |
Accepted Values |
Default |
| row |
row of the matrix |
Number |
- |
20 |
| col |
column of the matrix |
Number |
- |
10 |
| x |
X coordinate |
Number |
- |
0 |
| y |
Y coordinate |
Number |
- |
0 |
| Attribute |
Description |
Type |
Accepted Values |
Default |
| coordinate(getter) |
The coordinate of matrix |
Object |
โ |
{ x, y, array } |
| Method |
Description |
Parameters |
| reset |
reset matrix to initial state |
- |
MIT