Tetris has 7 parts, each of which occupies a different number and position of rectangles. Therefore, a component class is created and an array is created to store 7 parts, each part contains an array to store the number and position of the rectangle occupied by this part. The following is a detailed introduction.
Basic principles of this game:
The game area is a limited size area. The game area of this game has 21x25 rectangles, each of which is 10 in width, heght is 6 units (the absolute unit of canvas is fixed, not pixel ).
The create RusBlock class contains the corresponding data and behavior, and creates a two-dimensional array aState [21] [25] to record the marked rectangle in the game area.
Tetris has 7 parts, each of which occupies a different number and position of rectangles. Therefore, a component class is created and an array is created to store 7 parts, each part contains an array to store the number and position of the rectangle occupied by the part. When the falling part ends, a new part is generated, and the marked rectangle of the part is assigned to the array of the game area.
In the game loop function, print the falling parts, fixed parts, and the falling parts.
Basic knowledge:
HTML5 CSS JS
This game contains three files:
RusBlock.html: Set Element
RusBlock.css: Set the style
RusBlock. js: script control
Step 1: Set the interface and prepare materials
RusBlock.html
The Code is as follows:
RusBlock