Tetris game JavaScript code

Source: Internet
Author: User
Tags bitwise

JavaScript Code Tetris Game

I have long heard that someone on the internet just wrote a Tetris game with 60 lines of JavaScript code, and recently looked at it, and today in this article I have done my analysis (mainly in the form of annotations).

  

I use C to write a basic full-featured Tetris, it takes about 1000 lines of code to look like. So the 60 line at first glance is still very surprising.
But after reading the code, it turns out that the entire program does not use any arcane technology, but rather simplifies the code by using some tools or the techniques of JavaScript itself.

summed up mainly the following three points

1. Use eval to generate JavaScript code, reducing the volume of code
2. Use a string as the game scene data, using regular expressions to find and match, eliminating the usual should be manually written find validation code
3. Manage Tetris data and scene data in binary mode, simplifying comparisons and validations with bitwise operations
  

In addition, the original author code line is very small, the code is relatively compact, which is the result of this program only 60 lines of one reason.

Here's the code after my typeset comment.

  1 <!doctype html> 2 

The original author code is given below, 60 lines

 1 <!doctype html>

Category: C/

Tetris game JavaScript code

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.