JavaScript asynchronous programming in Russia (1)

Source: Internet
Author: User

RIS (RUSSIAN: р и) is a world-renowned TV game host and handheld game host, invented by Russian Alexei pakitov, therefore, this name is used. The basic rule of the Russian square is to move, rotate, and place various blocks automatically output by the game, so that they are arranged into one or more complete rows and the score is eliminated. It is easy to use and suitable for all ages, so it is widely used in the world.

BKJIA recommended topics: JavaScript asynchronous programming

Requirement Analysis]

(Completely based on the production of QQ games, for example :)

Technical Analysis and Implementation]

1. Locate the block position

Solution: Create a Box Model

Because of the existence of bars, a 4*4 box model is created, and any square will exist in the box. The positioning of the square is = the positioning of the box.

2. Generate and save the color status

Random color generation:

 
 
  1. Function randomColor (){
  2. // Hexadecimal representation of the color 0-F
  3. Var arrHex = ["0", "1", "2", "3", "4", "5", "6", "7", "8 ", "9", "A", "B", "C", "D", "E", "F"];
  4. Var strHex = "#";
  5. Var index;
  6. For (var I = 0; I <6; I ++ ){
  7. // Obtain a random integer between 0 and 15
  8. Index = Math. round (Math. random () * 15 );
  9. StrHex + = arrHex [index];
  10. }
  11. Return strHex;
  12. }

Save color: An Example of the status of the square)

 
 
  1. var diamonds = new Array();  
  2.    diamonds[0] = { x: appearPosition.position.x + 1, y: appearPosition.position.y, diamondColor: color };  
  3.    diamonds[1] = { x: appearPosition.position.x + 0, y: appearPosition.position.y + 1, diamondColor: color };  
  4.    diamonds[2] = { x: appearPosition.position.x + 1, y: appearPosition.position.y + 1, diamondColor: color };  
  5.    diamonds[3] = { x: appearPosition.position.x + 2, y: appearPosition.position.y + 1, diamondColor: color };  

All generated squares have a diamondColor attribute for color storage. AppearPosition. position is the position of the box model.


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.