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:
- Function randomColor (){
- // Hexadecimal representation of the color 0-F
- Var arrHex = ["0", "1", "2", "3", "4", "5", "6", "7", "8 ", "9", "A", "B", "C", "D", "E", "F"];
- Var strHex = "#";
- Var index;
- For (var I = 0; I <6; I ++ ){
- // Obtain a random integer between 0 and 15
- Index = Math. round (Math. random () * 15 );
- StrHex + = arrHex [index];
- }
- Return strHex;
- }
Save color: An Example of the status of the square)
- var diamonds = new Array();
- diamonds[0] = { x: appearPosition.position.x + 1, y: appearPosition.position.y, diamondColor: color };
- diamonds[1] = { x: appearPosition.position.x + 0, y: appearPosition.position.y + 1, diamondColor: color };
- diamonds[2] = { x: appearPosition.position.x + 1, y: appearPosition.position.y + 1, diamondColor: color };
- 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.