matrix -- A tool to operate the Array of two dimension

原创 lronelove 随笔 浅谈数据结构 134阅读 2018-10-30 08:49:02 举报


A tool to operate the Array of two dimension
It may be easy to handle the Array of one dimension because of the API that we know. But I may be hard to operate the Array of two dimension. So I thought about this when I wanted to make a game of snake. If I can change the data of the snake, It will be easy to make the game of snake.
That is just a example, now let's see how to use it.

1. install it

npm install matrix-lronelove --save

2. use it in your project

now you create a Array of two dimension with many functions in it.
for example, you can use matrix.set(1, 1, 'love'), It means you set col 1, row 1, with the value ,'love'.
But, be careful. To make it easy to use, the index starts at 1 not 0.

3.some functions to use

  • matrix.set(row, col, value) : set the data of matrix with value at (row, col)
  • matrix.changeRow(row1, row2): change two rows
  • matrix.addCol() : add one col
  • matrix.blockAnimate(row1, col1, row2, col2, right, top): It can make one block of the matrix to move. It is a very useful function.
  • and so on.There are so many useful functions to use. But I am lazy. When I am free, I will complete the doc.
评论 ( 0 )

赶紧努力消灭 0 回复