TC2.0 Writing Russian Square Games

xiaoxiao2021-03-06  42

TC2.0 Writing Russian square game Many programming enthusiasts have written programs for Russian squares. A long time ago, I did one with TC2.0; have recently had a good friend to see how I used the programs of the Russian square, asked me how to do it. I always want to write a detailed thing throughout the process of this program, share with friends, and have no time. Just a holiday now, and it is still a few days away from home. So I wrote this program again, try to make the program more clearly. At the same time, I wrote the following things. Some methods have been used in the program of Russian square games. In order to be more likely to understand these methods, I have written some sample programs that specifically target these methods while talking. These sample programs are short, and the purpose is to use the least code to be clearly used. These sample programs are tested by TC2.0. Finally, the source code of the Russian square game, and the final executable program. If you read this stuff, what kinds of comments and ideas, please send an email to tell me. I will continue to update this point of Dongdong, the latest version can be downloaded on my personal home page. The following question is about the Russian square program, some of which is a friend asking me, some, I think it may be asked. I tried to make these problems from the problem. Some problems about Russian square procedures: ***************************************** ************ How to set graphic display in TC2.0? How often use of a graphics function in TC2.0? How to get keyboard input? How to control the movement of the square? How to control time intervals (used for the drop of the shape of the game)? How to use data in various shapes and entire game space? How to determine the possibility of left and right and down movement in the game? How to determine the possibility of a certain shape rotation? Accelerate the processing of a certain shape drop speed when pressing down direction keys? How to determine how a certain shape is already? How to determine if a certain is filled? How can I eliminate a line that has been filled? How to eliminate all the rows that can be eliminated after a shape? (If the strip can eliminate four lines) How to modify the status of the game board? How to statistically? How to handle the upgrade acceleration problem? How to determine the end of the game? Questions about scoreboard design. Questions about "Next" shape tolls. The rest of the problem. *********************************************************** **** New question: I want to have a maximum record, what should I do? I want to implement a progress storage function, what should I do? How to set graphic display in TC2.0? There are two display modes in TC2.0, one is the character mode we are well known, and the other is graphical mode. You can only explicit characters in characters mode, such as ASCII characters. It is generally displayed 25 rows, 80 characters per row. The program default is character mode. Drawing operations cannot be explicitly graphically and drawing in character mode. To make a graphic display and drawing operation, you must switch to a graphical mode. TC2.0 can be switched to graphics mode in TC2.0, with closegraph () to switch to character mode from graphics mode. INITGRAPH () and closegraph () are graphical functions, which must include header files "graphics.h" using graphic functions. Void Far INITGRAPH; GRAPHTODRIVER; GRAPHDRIVER is a pointer to the graphical drive serial number variable; GraphMode is a pointer to the graphic display mode serial number after GraphDriver. Pathtodriver indicates the path to the storing graphics driver file.

There are several graphics drives in TC2.0, and there are several graphic display modes under each graphic drive. In my program, the graphics drive serial number is VGA, the graphic display mode serial number is VGAHI. This is a resolution of 640 * 480 (from left to right coordinates, 0-639 from top to bottom), and can display a graphics mode of 16 colors from the top to the lower coordinate. Other graphics drive serial numbers and graphical display mode serial numbers can be found from the manual or online help. Pathtodriver Indicates the path to store the graphics driver file. Different graphics drive serial numbers, graphics drive files are also different. The serial number is the VGA graphics drive corresponding to "Egavga.bgi" graphics driver file. "Egavga.bgi" is generally in the TC directory. Void Far Closegraph (Void); there is no parameters, returns the character mode from graphics mode. INITGRAPH () and closegraph () Common usage are as follows: int GDriver = VGA, GMODE = VGAHI, ERRORCODE; / * Initialize Graphics Mode * / Initgraph (& gdriver, & gmode, "e: // TC2"); / * Read Result of Initialization * / errorcode = graphresult (); if (ErrorCode! = GROK) / * An error Occurred * / {Printf ("Graphics Error:% S / N", GrapherrorMSG (ErrorCode)); Printf ("Press Any Key to Halt) : "); getch (); exit (1); / * return with error code * /} / * Return to text mode * / closegraph (); TC2.0 usage graphics functions Here, a graphic function for drawing used in several games: setColor (); line (); Rectangle (); setTextJustify (); outtextxy (); setFillStyle (); bar (); void Far SetColor (int Color ); Setting the line, picture frame, and the current color of the text in graphics mode. This function will affect the color of line (), rectangle (), and outtextxy () functions. Color can usually color constant: black? 0 Blue? 1 Green? 2 cyan? 3 red? 4 Magenta? 5 Brown? 6 LightGray? 7 Darkgray? 8 LightBlue? 9 LightGreen? 10 Lightcy? 11 LightRed? 12 LightMagenta? 13 YELLOW? 14 White? 15 Void Far Line (int x1, int y1, int x2, int y2); draws a line segment from (x2, y2) from (x1, y1) with the current color. Void Far Rectangle (INT LEFT, INT TOP, INT RIGHT, INT BOTTOM); Painting a rectangle box with current colors (LEFT, TOP), lower right corner (Right, Bottom). Void Far setTextJustify (int horz, int value) Set alignment in graphics mode. It mainly affects the OutTextxy () function.

horiz and vert desirable enumeration constants as follows:? horiz LEFT_TEXT 0 Left-justify text CENTER_TEXT 1 Center text RIGHT_TEXT 2 Right-justify text vert BOTTOM_TEXT 0 Justify from bottom CENTER_TEXT 1 Center?????????????? TEXT? TOP_TEXT? 2? Justify From Top Void Outtextxy (int X, int y, char * textstring); Use the current font (default font is default_font) in (x, y) display string TextString, string Alignment is specified by setTextJustify (). Void Far SetFillStyle (int pattern, int color); setting the fill mode of the graphics and fill colors, mainly affecting the BAR () and other functions. Pattern generally takes the enumeration of ordinary value Solid_Fill, and the value of Color is the same as the value of Color in SetColor (int coLor). Introduced the two issues, now to write a program. This program demonstrates several graphics functions described above. How does the program prog1.c get the keyboard input? In TC2.0, there is a function BIOSKEY (); INT BIOSKEY (INT CMD); when the CMD is 1, the bioskey () detects whether the key is pressed. There is no key to press it when it is pressed; the key is returned when the key is pressed (any button code is not 0), but the detected button code is not cleared from the keyboard buffer queue. When CMD is 0, Bioskey () returns the button code in the keyboard buffer queue and clears this button from the keyboard buffer queue. If the keyboard buffer queue is empty, it will wait until the key is pressed, and the obtained button code will be returned. The button code of the ESCAPE key is 0x11b, and the applet below can get the button code of the button. For (;;) {key = bioskey (0); / * Wait for a keyStroke * / printf ("0x% x / n", key); if (key == 0x11b) Break; / * escape * /} commonly used key of the key codes are as follows: #define VK_LEFT 0x4b00 #define VK_RIGHT 0x4d00 #define VK_DOWN 0x5000 #define VK_UP 0x4800 #define VK_HOME 0x4700 #define VK_END 0x4f00 #define VK_SPACE 0x3920 #define VK_ESC 0x011b #define VK_ENTER 0x1c0d complete procedure see prog2.c , PROG3.C. PROG2.C Get button of the button, press the ESCAPE button to exit the program. PROG3.C performs different operations according to different buttons, press the ESCAPE button to exit the program. How to control the movement of the square? The implementation of the square move is very simple, and the original position is painted with a background color, and the original square is applied. Then reopen the square in the new location. This enables the movement of the block. For a complete program, please refer to PROG4.C. This uses the arrow keys to control a yellow small square on the screen, down, left, and right. This program uses the content of the previous problems, if you have a little forgot, you have to look back. :) How to control the time interval (for the drop of the shape of the control shape in the game)? Solving this problem To use the clock interrupt. The clock interrupt is 18.2 times per second. After intercepted the normal clock interrupt, add a timing variable plus 1 after processing the normal clock interrupt. Thus, the variables per second increase by 18.

When you need to control the control time, you only need to see this timing variable. Intercept clock interrupts To use functions getVect () and setVect (). The declarations of the two functions are as follows: • VOID INTERRUPT (* getVect (int interruptno)) (); void setVect (int InterruptNo, Void Interrupt (* ISR) ()); reserved word interrupt indication function is an interrupt handler. All registers will be saved when calling the interrupt handler. The instructions when the interrupt processing function is returned is IRET, not the RET instruction used by the general function. GetVect () obtains the entry address of the interrupt handler of Interrupt INTERRUPTNO based on the interrupt number INTERRUPTNO. SetVect () Change the entry address of the interrupt handler of the interrupt number of Interrupt NO to the ISR () function. That is, the ISR () function will be called when an interruption occurs. At the beginning of the program, intercepted the clock interrupt and set new interrupt processing. At the end of the program, be sure to remember the recovery clock interrupt, otherwise the system's timing function will come out. Please refer to PROG5.C for the specific demo program. Since the interrupt is handled, everyone may use, so I put the proG5.c This program is completely attached to the bottom, and add a detailed explanation. / * prog5.c * / this is an interrupt service routine. You can not compile this program with get an executable file which will operate correlle. * / / * This program outputs an integer every 1 second After 10 seconds, the program is completed. Press the ESCAPE button to exit the program in advance. * / # incrude # include

#include

/ * Escape key * / #define vk_esc 0x11b #define Timer 0x1c / * clock interrupt interrupt number * / / * interrupt handler is slightly different in C and C . If _cplusplus is defined in the C environment, it will be in the C environment. * / #ifDef __cplusplus #define __cppargs ... #define __cppargs #ENDIF INT TIMERCOUNTER = 0; / * Time variable, increase 18 per second. * / / * Pointing the interrupt processing function pointer (handle) * / void interrupt (* OldHandler) (__ cppargs); / * new clock interrupt processing function * / void interrupt newHandler (__ cppargs) {/ * Increase the global counter; / * call the old routine * / oldhandler ();} / * Set new clock interrupt processing * / void setTimer (VOID INTERRUPT (* INTPROC)) {oldhandler = getVect Timer; disable (); / * When setting new clock interrupt processing, all interrupts * / set, intProc; enable (); / * Open interrupt * /} / * Restore the original clock interrupt processing Procedure * / void killtimer () {disable (); setVect (time, oldhandler); enable ();} void main (void) {int key, time = 0; setTimer (NewHandler); / * Modify Clock Interrupt * / for (;;) {if (Bioskey (1)) {key = bioskey (0); if (key == vk_esc) / * Press the ESCAPE button to exit the program * / {Printf ("User Cancel! / N"); Break }}}} IF (TimerCounter> 18) / * 1 second processing once * / {/ * recovery timing variable * / TimerCounter = 0; TIME ; Printf ("% D / N", TIME); if (Time == 10 ) / * After 10 seconds, the program * / {printf ("program terminated normally! / N"); break;}}} killtimer (); / * Recovery clock interrupt * /} games in the game and the entire game How to use data? The shape I mentioned later refers to a variant of seven in seven shapes and their rotation. □□□□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■ □ □ ■ □□ □ ■ □ □ □ ■ □ □ □ ■ ■ □ □ ■ □ ■■■ □ ■■ □□ □□□□ □ ■ □□ □ □ □ □ □ □ □ □ ■ □ □ □ □ □ ■ □ □ □ ■ □ □ □ ■ □ □ ■■ □ □ ■ □□ ■ ■ □ I defined a structure to represent the shape. Struct Shape {INT XY [8]; int color; int next;} -1 0 1 2 -3 □□□□ -2 □□□□ -1 □□□□ 0 □ ■ □ □ all the shapes Can be placed in the 4x4 lattice. Assuming the second column, the lattice coordinates of the fourth line are (0, 0) (as shown in the figure above), and four squares of each shape can be represented by four. The coordinate X increases from the left to the right, Y is incremented from top to bottom. When it is, four blocks constituting the shape are from left to right, from top to bottom (not necessarily, according to this order).

The first number of times of the seven shapes above is represented (-2, 0), (- 1, 0), (0), (1, 0). The XY in the structure shape is used to indicate these 4 numbers. In order to simplify the program, use the one-dimensional array xy [8]. XY [0], XY [1] represents the first number, XY [2], XY [3] represents the second number, and it is pushed. Color in Shape represents the color of shape, different shapes with different colors. There are 19 shapes in seven shapes and their rotation, and a global array is represented by a global array. It is assumed that the direction of rotation is counterclockwise direction (like clockwise direction). NEXT in Shape indicates the serial number of the next shape after rotating the current shape counterclockwise. For example, the shape structure of the first shape and its rotational deformation is shown below. □□□□ □ □ □ □ □ □ □ □ □ □ □ ■ □ □ □ □ □ □ ■ □ □ □ ■ □ □ ■ □ ■■■ □ □ ■ ■ □ ■ ■ □ □ □ ■ □ ■ □□□ Struct Shape shapes [19] = {/ * {x1, y1, x2, y2, x3, y3, x4, y4, color, next} * / {0, -2, 0, -1, 0, 0, 1, 0, CYAN, 1}, / * / {-1, 0, 0, 0, 1, -1, 1, 0, Cyan, 2}, / * # * / {0, -2, 1, -2, 1, -1, 1, 0, cyan, 3}, / * # * / {-1, -1, -1, 0, 0, -1 , 1, -1, cyan, 0}, / * ## * / ...} The game space refers to the main interface of the entire game (huh, I really can't think of more accurate, please General pointer). In fact, a width 10 plaid, a player of 20 lattice. Expressed with a global array BOARD [12] [22]. When it is said: Board [x] [Y] is 1 when it indicates that there is a block on the game board (x, y), and Board [x] [y] is 0 indicates that this location is sealed on the game board. . In order to facilitate the determination of the movement of the shape to the side, in the end, the initial time adds a column on both sides of the game board, plus a line below the gaming board, and fill in 1, indicating that the boundary cannot be removed. That is, Board [0] [Y], Board [11] [Y] is initially 1, and Board [x] [21] (where X from 1 to 10) is initially 1. 1 2 3 4 5 6 7 8 910 1 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□ 5 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□ 14 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□ 19 □ □ □ □ □ □ □ □ □ 20 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ Although the program is slightly longer, it is not particularly complicated. Where the game board initialization is not truly used, but the next step is used. Where SIZE is defined as 16 so that the coordinate system of the entire screen is converted to 40 × 30 (640/16 = 40, 480/16 = 30) by the original 640 × 480 (640/16 = 40, 480/16 = 30). All coordinates in the game are based on 40 × 30 coordinate system, which helps to simplify the program. The conversion of the coordinates is manifested by DrawBlock (int X, int y) in the program.

The new coordinate system is shown below: -8-7-6-5-4-3-2-1 0 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031 -4 □□□□□□□□□□□□□ □□□□□□□□□□□□□□□□□□□□□□□□□□□ -3 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□□□□□□□□□□□□□ -2 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□□□□□ -1 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□ 0 □□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□ □ □ □ □ □ □ □ □ □ □ □ □□□□ ■■■■■■■■■■■ □□□□□□□□□□□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■■■■■ ■■■■■ □□□□□□□□□□□□□□□□□□□□□ □ □ □ □ □ □ ■■■■■■■■■■■■ □ □ ■ ■■■ □□□□□□□□□□□□□□ □ □ □ □ □ □ □ ■■■■■■■■■■■ □□□ ■■■■ □ □ □ □ □□□□□□□□ 5 □□□□□□□□□ ■■■■■■■■■■■ □□□ ■■■■ □□□□□□□□□□□□□ □□□□□□□□□ ■■■■■■■■■■■ □□□ ■■■■ □□□□□□□□□□□□□□ 7 □ □ □ □ □ □ □ ■■■■■■■■■■ □□□□□□□□□□□□□□□□□□□□□ ■■■■■■■■■ ■ □□□□□□□□□□□□□□□□□□□□□ 9 □ □ □ □ □ □ □ ■■■■■■■■■■■■ □ □ □ □ □ □ □ □□□□□□□□□□□□□ 10 □ □ □ □ □ □ □ ■■■■■■■■■■■■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□ 11 □□□□□□□□□ ■■■■■■■■■■■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□ ■■■■■■■■■■■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■■■■ ■■■■■■ □□□□□□□□□□□□□□□□□□□□□ 14 □ □ □ □ □ □ ■ ■ ■ ■ ■ ■ ■ □□□ □□□□□□□□□□□□□□□□□□ 15 □ □ □ □ □ □ □ ■■■■■■■■■■■ □□□□□□□□□□□ □□□□□□□□□ 16 □ □ □ □ □ □ □ ■■■■■■■■■■■■ □□□□□□□□□□□□ 17 □□□□□□□□□ ■■■ ■■■■■■■ □□□□□□□□□□□□□□□□□□□□□ 18 □ □ □ □ □ □ ■ ■ ■ □ ■ ■ ■ ■ □ □ □□□□□□□□□□□□□□□□□□□ 19 □ □ □ □ □ □ □ ■■■■■■■■■■■■ □□□□□□□□□□ □□□□□□□□□□□ 20 □ □ □ □ □ □ □ ■■■■■■■■■■■ □□□□□□□□□□□ □ 21 □□□□□□□□□□□□□□□□□□□□□□□□□□□□□□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□□□□□□□□□□□□□□□□□□ 24 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□□□□□□□□□□ 25 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□□ 26 □□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□ □ new coordinates The most important thing is to have two black parts above. The big thing on the left is the game board (the abscissa from 1 to 10, the ordinate from 1 to 20), the small right is the "next" shape (the abscissa from 14 to 17, the conjunction is from 3 Between 6). This new coordinate system is the foundation of the entire game, and all of the movements, deformation, and the like are based on this coordinate system. How to determine the possibility of left and right and down movement in the game? I understand the representation of the various shapes and game boards, and the next thing is better. Let's take a look at how a shape is displayed in the game board. Suppose you want to display the first shape in the game board.

The first shape is shown in the structure as follows: Struct Shape Shapes [19] = {/ * {x1, Y1, X2, Y2, X3, Y3, X4, Y4, Color, Next} * / {0, -2, 0, -1, 0, 0, 1, 0, Cyan, 1}, ...} The coordinates of the four squares of this composition is expressed as (0, -2), (0, -1), (0,0 ) And (1, 0). This is actually a relative coordinate. The actual coordinate of the fake shape refers to the second column in the 4x4 square, and the position of the third line is located, and this location is (x, y). The actual coordinate of the four small squares that make up this shape (as an example of first shape) is (x 0, y-2), (x 0, y-1), (x 0, y 0 ) And (x 1, y 0). Since all shapes can be represented in the square array of 4x4, this will find a unified approach to represent all shapes. -1 0 1 2 -3 □□□ □ Relative coordinate-2 □ ■ □□ -1 □ ■ □ □ Component the relative coordinates of the four squares of the first shape (0, -2), (0, -1 ), (0, 0) and (1, 0). 0 □ ■■ Let us see how the shape is displayed in the gambo board (as an example of the first shape). 1 2 3 4 5 6 7 8 910 1 □ ■ □ □ □ □ □ □ □ Shaped coordinates are (2, 3). The coordinates of the four squares that make up the shape are drawn from the shape of 2 □ ■ □□□□□□□ □ Coordinates plus the respective relative coordinates of these four small squares. They are: 3 □ ■■ □□□□□□□ (2 0, 3-1), (2 0, 3-0) and (2 1, 3-0). That is: 4 □□□□□□□□□□ (2, 1), (2, 2), (2, 3) and (3, 3). As shown in the left. 5 □ □ □ □ □ □ □ □ 6 □ □ □ □ □ □ □ □ 7 ■ □□□□□□□□□ Shape coordinates are (1, 9). The coordinates of the four squares that make up the shape are: 8 ■ □□□□□□□□□ (1 0, 9-2), (1 0, 9-1), (1 0, 9-0 ) And (1 1, 9-0). That is: 9 ■■ □□□□□□□□ (1, 7), (1, 8), (1, 9) and (2, 9). As shown in the left. 10 □□□□□□□□□□ 11 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□ 15 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■ □ Shape The coordinates are (9, 20). The coordinates of the four squares of the shape are: 19 □□□□□□□□ ■ □ (9 0, 20-2), (9 0, 20-1), (9 0, 20-0 ) And (9 1, 20-0). That is: 20 □□□□□□□□ ■■ (9, 18), (9, 19), (9, 20) and (10, 20). As shown in the left. From now on, I will no longer have another sample program. From now on, all sample code is from "Russia.c" I wrote. In order to record the status of the game board, a global array BOARD [12] [22] is used. Board [x] [Y] (where x from 0 to 11, Y from 1 to 21) is equal to 1 indicating (x, y) This position has been filled, and the coordinates of the four squares constituting shapes cannot be (x, Y), otherwise conflicts will occur. Board [x] [Y] (where x from 1 to 10, Y from 1 to 20) is equal to the representation (x, y) this location has not been filled. When the game board is initialized, give Board [0] [Y], Board [11] [Y] is assigned to 1, which is assigned to 1, give Board [x] [21] (where X from 1 to 10) Both are assigned to 1. This is equivalent to adding a "edge" to the gaming board at the beginning. All shapes cannot be moved into this "side", otherwise conflicts will occur.

Now we can start discussing how to determine the possibility of moving to the left, right and downward movement. Let's talk about a concept, "Current shape" means the shape that is falling yet. If the current shape moves to the left, it is not possible to conflict with the existing state of the game board. The specific approach is to assume that the current shape has moved left, and it is judged whether or not conflicting with the existing status of the game board. If a conflict does not occur, you can move left. Otherwise, it is not possible to move left. It is determined that the code of the index number of ShapeIndex in the coordinates (X, Y) is as follows, and the code conflicts with the current state of the game board. I add a detailed explanation to this code. ENUM BOOL Confilic (int ShapeIndex, Int x, int y) {INT i; / * Judies out * / for (i = 0; i <= 7; i , i ) / * i takes 0, 2, 4, 6 * / {/ *, if there is any one of the X coordinates of any of the four blocks less than 1 or greater than 10, indicating that the left boundary or right boundary is indicated. At this time, a conflict occurs. * / if (Shapes [ShapeIndex] .xy [i] x <1 || Shapes [ShapeIndex] .xy [i] x> 10) Return True; / * If the Y coordinate of a square in four squares is less than 1. It is said that the entire shape has not completely fallen into the game board. At this time, it is not necessary to judge this block. * / if (Shapes [ShapeIndex] .xy [i 1] Y <1) Continue; / * If there is any block in four squares conflict with the current state of the game board, the entire shape is in (x, y) Current state conflict with the game board * / if (Board [Shapes [ShapeIndex] .xy [i] x] [Shapes [ShapeIndex] .xy [i 1] y]) Return True;} / * four squares There is no block in any block in the current state of the game board, and the entire shape does not conflict with the current state of the gameboard in (x, y) * / return false;} Additional descriptions are added to the above code: Shapes [ShapeIndex] .xy [ i] (where i is equal to 0, 2, 4, 6) indicates the X relative coordinates of a piece of a square that computes the shape of the index number of ShapeIndex. (When I is equal to 0, the X opposing coordinate of the first square block; i is equal to 2, indicating the X opposing coordinates of the second square block; i is equal to 4, indicating the X opposing coordinates of the third block; i is equal to 6 Represents the X-relative coordinates of the fourth square.) Shapes [ShapeIndex] .xy [i] (where i is equal to 1, 3, 5, 5) indicates a relative coordinate of the Y relative coordinates of a square of the shape of the index number ShapeIndex. (When I is equal to 1, the Y relative coordinate of the first square block; i is equal to 3, indicating the Y relative coordinate of the second square block; i is equal to 5, indicating the Y-relative coordinate of the third block; i is equal to 7 Represents the Y relative coordinates of the fourth square.) Shapes [ShapeIndex] .xy [i] x (where i is equal to 0, 2, 4, 6) indicates the coordinates of the shape of the index number ShapeIndex (x, y) When constituting the X actual coordinates of a square of the shape. (When i is equal to 0, the X actual coordinate of the first square; i is equal to 2, indicating the X actual coordinates of the second square block; i is equal to 4, indicating the X actual coordinate of the third block; i is equal to 6 , Indicating the X actual coordinates of the fourth square.

) Shapes [ShapeIndex] .xy [i] y (where i is equal to 1, 3, 5, 7) indicates a number of squares of the shape when the index number of ShapeIndex is (x, y). Y Actual coordinates. (When i is equal to 1, the Y actual coordinate of the first square; i is equal to 3, indicating the Y actual coordinate of the second square; i is equal to 5, indicating the Y actual coordinate of the third part; i is equal to 7 , Indicating the actual coordinates of the fourth square.) What does this sentence mean now. Board [Shapes [ShapeIndex] .xy [i] x] [Shapes [ShapeIndex] .xy [i 1] y] can be understood, separate the above sentence :: actualx = shapes [shapeindex] .xy [ i] x; / * where x is 0, 2, 4, 6 * / represents a square actual X coordinate. Actual = [Shapes [ShapeIndex] .xy [i 1] y; represents a physical Y coordinate. Board [actualx] [actual] is the logo of the game board that is the same as a square coordinate. If this flag is not 0 (1), this block is conflicted with the game board. If this flag is 0, it means that this block has no conflict with the game board. This is relatively long, but it is not particularly difficult to understand. Many places in the game use this relative coordinate to the actual coordinates, understand this paragraph is very helpful in understanding the code to understand other parts. After reading this code, you may mention a question: Isn't it already added "side" on both sides of the game board, why should I add this to the X coordinate judgment? / * If there is any one of the X coordinates of any block in four squares less than 1 or greater than 10, it means exceeding the left boundary or right boundary. At this time, a conflict occurs. * / if (Shapes [ShapeIndex] .xy [i] x <1 || Shapes [ShapeIndex] .xy [i] x> 10) Return True; this is because there is a special case, as shown below: ■ ■ ■ 2 3 4 5 6 7 8 910 1 ■ □ □ □ □ □ □ □ □ This is likely to happen when it is currently coming out. But we only give the game board 2 □ □ □ □ □ □ □ □ □ For the leftmost block of this shape, it will lose judgment, 3 □□□□□□□□□□ If you don't pay, this shape will "hang" on the upper left corner of the game board! At the beginning, I didn't think of this, and I didn't expect this, then I found that there will be "hanging" in the top, and lead to the game 5 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ I found this problem. 6 □□□□□□□□□□ 7 □ □ □ □ □ □ □ □ 8 □ □ □ □ □ □ □ □ □ Add this judgment, the two "edge" of the game board conflict The judgment is that it is to get 9 □□□□□□□□□ □. Because there is no two "edges", it will not be wrong for the conflict. However, 10 □ □ □ □ □ □ □ □ □ For the procedure easy to understand, or retain the left and right "edges" of the game board. 11 □□□□□□□□□□ 12 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□□□□ 16 □□□□□□□□□□ 17 □ □ □ □ □ □ □ □ 18 □ □ □ □ □ □ □ □ 19 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ 20 □ □ □ □ □ □ □ □ □ If you have new problems you put forward above and the explanation of this problem, it is not important.

转载请注明原文地址:https://www.9cbs.com/read-51458.html

New Post(0)