HTML5 + JS Implementation of Tetris principles and specific steps _ html5 tutorial skills-

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.