俺 俺 天 方 方 程序 方 方 程序 程序 方 方 方

zhaozj2021-02-16  49

/ * TC3 is debugged, before compiling, take the egavga.bgi of the TurboC directory to the directory where the source program is located. In addition * /

#include / * Define Boland Graphics * / # include #include #include #include #define ESC 0x11b / * definition Keyboard scanning code * / # define up 0x4800 # define down 0x5000 # define left 0x4b00 # define f1 0x3b00 # define right 0x4d00 # define yes 0x1579 # Define no 0x316e # define restart 0x1372 / *********** ******** Define global variables **************************************** / INT GRID [20] [10]; / * Grid array, 0 indicates that there is no square, 1 has a moving square, 2 has a stationary square * / int level, score, interval; / * level, score, the number of layers, Interval - Drop time interval (unit milliseconds) * // ****************************************************** *************************************** / Static I_Shape1 [1] [4] = {1, 1, 1, 1} / * I represents the long strip, O-square * / static int = = {1, 1, 1, 1}; static int o_shape [2] [2] = {1, 1, 1, 1}; Static Int T_Shape1 [2] [3] = {1, 1, 1, 0, 1, 0}; static int T_shape2 [3] [2] = {0, 1, 1, 1, 0, 1}; static int T_Shape3 [2] [3] = {0, 1, 0, 1, 1, 1}; static int T_shape4 [3] [2] = {1,0, 1, 1, 1, 10} Static int L_Shape1 [3] [2] = {1,0, 1,0, 1, 1}; static int L_Shape2 [2] [3] = {1, 1, 1, 1, 0, 0}; static int L_Shape3 [3] [2] = { 1, 1, 0, 1, 0, 1}; static int L_Shape4 [2] [3] = {0, 0, 1, 1, 1, 1}; static int J_Shape1 [3] [2] = {0, 1, 0, 1, 1, 1}; static int j_shape2 [2] [3] = {1,0,0, 1, 1, 1}; static int j_shape3 [3] [2] = {1, 1, 1, 0, 1, 0}; static int j_shape4 [2] [3] = {1, 1, 1, 0, 0, 1}; static int z_shape1 [2] [3] = {1, 1, 0, 0, 1, 1}; static int z_shape2 [3] [2] = {0, 1, 1, 1, 1, 0}; static int n_shape1 [2] [3] = {0, 1, 1, 1, 1,0}; static int n_shape2 [3] [2] = {1,0, 1, 1, 0, 1};

/ *********************************************************************************************************** ************ / STRUCT block {char TYPE; / * The type of square, a total of I, O, T, L, J, Z, N seven types * / int Shape; / * Specific shape of the species * / int X; / * The upper left side of the square * / int y; / * The upper left side of the square is the upper left side of the horizontal tone * / INT color; / * square color * /}; / ** *********************************************************** *********** / INI_GRAPH (); / * Initializes the connection of the graphic library GRAPHIC.H Database * / int check_bottom (); / * Decision whether the block is in the bottom of the container or there is no other Square, there is a return 1, otherwise returns 0 * / int check_top (); / * Decision whether the square is to the top, but also the game end sign * / int check_lborder (); / * Decision whether the block is on the left edge of the container to the left or left. Other squares * / int check_rboorder (); / * Decision whether the square is on the right edge of the container or other squares * / int del_line (); / * Judging whether a line is full, if full, return 1, Otherwise, returning 0 * / void initial (); / * Initialize all global variables and interfaces * / void restart (); / * When the game is over, ask the user to exit or play * / void help (); / * Display button help Information * / void showScore (); / * Display interface * / void test (); / * Test Grid [i] [j] debug function * / void drawbar (); / * Painting game container * / Void ini_grid (); / * Painting in the lattice * / void show_next (); / * Display the next piece of information on the top right * / void DrawBlock (); / * Painting Square * / void clear_block (); / * Clear square * / void printscore (); / * Print score and correction * / struct block create (); / * Random generate a new block * / Struct Block change (); / * Rotary transform function * // * ********************************************************** ************ / VOID Main () {int key; / * User button * / Struct Block nextblock, mblock; / * nextblock - Next block, MBLOCK - now square * / initial (); Help (420, 200); showscore (); Printscore (); nextblock = Create (); loop: if (CHECK_TOP (MBLOCK)) Restart (); / * If the square does not leave the container top, perform loop loop * / printscore (); mblock = obtained (); NextBLOCK = Create (); Show_next; while (1) {if (Bioskey (1)! = 0) Key = bioskey (0); Else Key = 0; switch (key) {copy down: {if (check_bottom (mblock) == 1 ) {If (! Del_line (mblock.y)) {mblock.color = darkgray; drawblock (mblock);} goto loop;} clear_block (mblock); mblock.y = mblock.y 20; DrawBlock (mblock);} Break;

Case Up: Mblock = Change (Mblock); Break; Case Left: IF (! Check_lbock) &&! Check_bottom (Mblock) {CLEAR_BLOCK (Mblock); mblock.x- = 20;} Break; Case Right: IF ( CHECK_RBORDER (MBLOCK) {CLEAR_BLOCK (MBLOCK); MBLOCK.X = 20;} Break; Case F1: Test (); Break; Case Esc: SetFillStyle (1, Darkgray); BAR (0,465,640,480) Outtextxy (5,469, "Are you sudu to exit (y / n) ..."); while (1) {key = bioskey (0); if (key == no) {ion (); HELP (420, 200) Showscore (); printscore (); goto loop;} if (key == yes) {closegraph (); exit (1);}} Break; default: {if (check_bottom (mblock) == 1) {IF Del_line (mblock.y)) {mblock.color = darkgray; drawblock (mblock);} goto loop;} clear_block (mblock); mblock.y = mblock.y 20; DrawBlock (Mblock); delay (interval); }} / * Switch * /} / * while * /} / * main * // * Initializes all global variables and interfaces * / void initial () {INT I, J; score = 0; interval = 500; for (i = 0; i <20; i ) For (j = 0; j <10; j ) grid [i] [j] = 0; INI_GRAPH (); DrawBar (); INI_GRID ();} / * drawing game container * / void drawbar () {int LEFT , Top, Right, Bottom; LEFT = 200; TOP = 40; Right = 400; Bottom = 440; SetFillStyle (1, LightBlue); Bar (Left, Top, Right, Bottom); BAR (480, 40, 560, 120);} / * On the lattice * / void ini_grid () {INT I, J; For (i = 0; i <10; i ) for (i = 0; J <20; J ) {Rectangle (200 ; J <20; J ) {Rectangle i * 20, 40 j * 20, 200 i * 20 20, 40 j * 20 20); / * Painted lattice * /} for (i = 0; i <4; i ) for (J = 0; J <4; J ) Rectangle (480 i * 20, 40 J * 20, 480 i * 20 20, 40 J * 20 20);

/ * Painting Show the next block of lattice * /} / * randomly generate a new square * / Struct Block Create () {struct block newblock; int R; r = random (7); switch (r) {casse (0 : newblock.type = 'i'; newblock.color = 5; Break; case (1): newblock.type = 'o'; newblock.color = blue; break; case (2): newblock.type = 't '; newblock.color = brown; break; case (3): newblock.type =' l '; newblock.color = YELLOW; Break; case (4): newblock.type =' j '; newblock.color = lightgreen; Break; Case (5): newblock.type = 'z'; newblock.color = green; break; case (6): newblock.type = 'n'; newblock.color = red; break;} newblock.shape = 1 Newblock.x = 300; newblock.y = 40; return newblock;} / * Dissure function, transfer parameter is the longitudinal coordinate value of the upper left side of the block, if there is a finish, return 0, otherwise return 1 * / int Del_Line (int TY) {INT I, J, B, I0, K, RET; RET = 0; if (Ty> = 440) Return 0; I0 = (TY-40) / 20; IF (I0 == 19 || I0 == 18 || I0 == 17) B = 19; ELSE B = I0 3; For (k = I0; K <= B; K ) {for (j = 0; j <10; J ) IF ( Grid [k] [j]) Break; if (j == 10) {score ; RET = 1; for (i = k; i> 0; I -) for (j = 0; j <10; J ) ) {Grid [i] [j] = grid [i-1] [j]; if (! Grid [i] [j]) {setfillstyle (1, lightblue); setColor (White); Rectangle 200 J * 20, 40 I * 20, 200 J * 20 20, 40 i * 20 20); FloodFill (200 J * 20 10, 40 i * 20 10, White);} else {setfillstyle; setColor (Darkgray); Rectangle (200 J * 20, 40 i * 20, 200 J * 20 20, 40 i * 20 20); floodfill (200 j * 20 10,40 i * 20 10, DARKGRAY);}}}} return ret;} / * block determines whether the container has been left or left other block, there is return to 1, 0 otherwise to pass parameters Current Block structure instance variable,

* / Int Check_lborder (struct block cblock) {Int I0, J0; J0 = (CBLock.x-200) / 20; I0 = (CBLock.y-40) / 20; if (CBLock.x <= 200) Return 1 ; / * Already reached the left boundary * / switch (cblock.Type) {case ('i'): if (Grid [i0] [j0-1]) Return 1; Break; / * There are other stationary sides on the left * / Case ('o'): IF (Grid [I0]) RETURN 1; Break; Case ('L'): Switch (CBLock.Shape) {Case (1): IF (Grid [ I0] [J0-1] || Grid [i0 1] [J0-1] || Grid [i0 2] [J0-1]) Return 1; Break; Case (2): IF (Grid [I0] [J0-1] || Grid [I0 1] [J0-1]) Return 1; Break; Case (3): IF (Grid [I0] [J0-1] || Grid [i0 1] [J0 ] || Grid [I0 2] [J0]) Return 1; Break; Case (4): IF (Grid [I0] [J0-1] || Grid [i0 1] [J0-1]) Return 1 Break;} Break; Case ('J'): switch (cblock.shape) {case (1): IF (Grid [i0] [j0] || grid [i0 1] [j0] || grid [i0 2] [J0-1]) Return 1; Break; Case (2): IF (Grid [I0] [J0-1] || Grid [i0-1] [J0-1]) Return 1; Break; Case (3): IF (Grid [I0] || Grid [I0 1] [J0-1 || Grid [I0 2] [J0-1]) Return 1; Break; Case (4 : IF (Grid [I0] [J0-1] || Grid [I0 1] [J0 1]) Return 1; Break;} Break; Case ('t'): Break; Case ('Z'): Break; Case ('n'): Break;}

RETURN 0;} / * If the block is to the right border or other squares of the container, there is another square, and there is a return 1, otherwise returns 0 Transfer parameters for the current Block structure instance variable, * / int Check_rborder (Struct Block CBLOCK) {INT I0, J0; J0 = (CBLOCK.X-200) / 20; / * Cut the coordinate X, Y of the left side of the block into the corresponding array GRID [I] [J] subscript I0, J0 * / I0 = (CBLOCK.Y-40) / 20; switch (cblock.Type) {case ('i'): if (CBLock.Shape == 1) {IF (CBLock.x 80> = 400 || Grid [I0 ] [J0 4]) RETURN 1;} / * Already reached the right border or left existing block * / else {= = 400 || Grid [i0] [j0 1]) Return 1;} Break; Case ('o'): IF (CBLOCK.X 40> = 400 || Grid [i0] [J0 2] || Grid [i0 1] [J0 2]) Return 1; Break; case ('t'): switch (cblock.shape) {case (1): if (CBLock.x 60> = 400 || Grid [i0] [J0 3] || Grid [i0 1] [J0 2]) Return 1; Break; Case (3): IF (CBLock.x 60> = 400 || Grid [i0 1] [J0 3] || Grid [i0] [j0 2] RETURN 1; Break;

Case (2): if (CBLOCK.X 40> = 400 || Grid [i0] [J0 2] || Grid [i0 1] [J0 2] || Grid [i0 2] [J0 Return 1; Break; Case (4): IF (CBLock.x 40> = 400 || Grid [i0] [J0 1] || Grid [i0 2] [J0 1] || Grid [I0 1] [J0 2]) Return 1; Break;} Break; Case ('L'): Switch (CBLOCK.SHAPE) {Case (1): IF (CBLock.x 40> = 400 || Grid [i0 2] [J0 2] || Grid [i0] [J0 1] || Grid [i0 1] [J0 1]) Return 1; Break; Case (2): IF (CBLOCK. X 60> = 400 || Grid [i0] [J0 3] || Grid [i0 1] [J0 3]) Return 1; Break; Case (3): IF (CBLock.x 40> = 400 || Grid [I0] [J0 2] || Grid [i0 1] [J0 2] || Grid [i0 2] [J0 2]) Return 1; Break; Case (4): IF (CBLOCK.X 60> = 400 || Grid [I0] [J0 3] || Grid [i0 1] [J0 3]) Return 1; Break;} Break; Case ('J'): Switch (CBLOCK.SHAPE) {case (1): if (CBLOCK.X 40> = 400 || Grid [i0] [J0 2] || Grid [i0 1] [J0 2] || Grid [I0 2] [J0 2]) Return 1; Break; Case (2): IF (CBLock.x 60> = 400 || Grid [i0] [J0 1] || Grid [i0 1] [J0 3]) Return 1; Break; Case (3): IF (CBLock.x 40> = 400 || Grid [i0] [j0 2] || Grid [i0 1] [j0 1] || Grid [i0 2] [J0 1]) Return 1; Break; Case (4): IF (CBLOCK.X 60> = 400 || Grid [i0] [J0 3] || Grid [i0 1] [J0 3]) Return 1; Break;} Break; Case (' Z '): Switch (cblock.shape) {case (1): if (CBLock.x 60> = 400 || Grid [i0] [j0 2] || Grid [i0 1] [j0 3] ) RETURN 1; Break; case (2): if (CBLock.x 40> = 400 || Grid [i0] [j0 2] || Grid [i0 1] [j0 2] || Grid [I0 2] [J0 1]) Return 1; Break;} Break; Case ('N'

: Switch (CBLOCK.SHAPE) {case (1): if (CBLock.x 60> = 400 || Grid [i0] [J0 3] || Grid [i0 1] [J0 2]) Return 1; Break; Case (2): IF (CBLOCK.X 40> = 400 || Grid [i0] [J0 1] || Grid [i0 1] [J0 2] || Grid [i0 2 ] [J0 2]) Return 1; Break;} Break;} return 0;} / * Rotary transform functions, one of the core programs of this game, transmit parameters as the current Block structure instance variable, determine if the current location can be After the transformation, if you can return the converted Block instance variable, you return the original BLOCK instance variable * / struct block change (struct block cblock) {INT i, J, I0, J0; J0 = (CBLock.x- 200) / 20; / * Cut the coordinate X, Y of the left side of the block into the corresponding array Grid [i] [j] subscript I0, J0 * / I0 = (CBLock.y-40) / 20; switch (Switch) CBLOCK.TYPE) {Case ('I'): switch (cblock.shape) {case (1): IF (Grid [i0 2] [j0 1] || Grid [i0 3] [j0 1] ) Return CBLOCK; CBLOCK.X = 20; CBLock.Shape ; Break; Case (2): IF (Grid [I0] [J0-1] || Grid [i0] [J0 1] || Grid [I0] [J0 2] || CBLock.x> = 360 || CBLock.x <= 200) Return CBLOCK; / * If there is already other squares after transform, or the rear block is exceeded if it is not changed * / Clean_block (cblock); cblock.x- = 20; / * Otherwise, the original block, calculate the change new coordinate * / cblock.shape -; / * The same type of square enters the next shape * / Break;} Break; Case ('t'): switch (cblock.shape) {case (1): IF (Grid [i0-1] [j0 1]) Return CBLock; CLOAR_BLOCK (CBLOCK); CBLock.y- = 20; cblock.shape ; break; case (2): if (CBLock.x> = 360 || Grid [i0 1] [J0 2]) Return CBLOCK; CLOAR_BLOCK (CBLOCK); CBLock.Shape ; Break; Case (3): IF (Grid [I0-1] || Grid [i0] [J0 2]) Return CBLOCK; CLOCK.X = 20; cblock.y- = 20 ; CBLock.Shape ; Break; Case (4): IF (CBLOCK.X <= 200 || Grid [i0

1] [J0-1]) Return CBLOCK; CBLOCK.Y = 20; CBLock.x- = 20; CBLock.Shape = 1; Break;} Break; Case ('L'): Switch (CBLOCK) .Shape) {case (1): IF (Grid [i0 2] [j0-1] || Grid [i0 1] [J0 1] || CBLock.x <= 200) Return CBLOCK; CLOAR_BLOCK (CBLOCK ); cblock.y = 20; cblock.x- = 20; cblock.shape ; break; case (2): IF (Grid [i0-1] [j0] || grid [i0-1] [j0 1] || Grid [I0 1] [J0 1]) Return CBLOCK; CBLOCK.Y- = 20; CBLock.Shape ; Break; Case (3): IF (Grid [i0 2] [J0 -1] || Grid [i0 2] [J0] || CBLock.x <= 200) Return CBLock; CLOAR_BLOCK (CBLOCK); CBLock.x- = 20; CBLock.Shape ; Break; Case (4): IF (Grid [I0] [J0 1] || Grid [i0-1] [J0 1]) Return CBLock; CLOAR_BLOCK (CBLOCK.Y- = 20; CBLock.x = 20 CBLock.Shape = 1; Break;} Break; Case ('J'): switch (cblock.shape) {case (1): if (Grid [i0 1] [j0] || grid [i0 2] [J0 2] || CBLOCK.X> = 360) Return CBLOCK; CLEAR_BLOCK (CBLOCK); CBLOCK.SHAPE ; Break; Case (2): IF (Grid [I0-1] [J0 1] || Grid [i0-1] [j0]) Return CBLOCK; CLEAR_BLOCK (CBLock); CBLock.y- = 20; cblock.shape ; Break; case (3): IF (Grid [i0 1] [j0 1] || Grid [i0 2] [j0 1] || Grid [i0 1] [J0-1]) Return CBLOCK; CBLOCK.Y = 20; CBLock.x- = 20; IF (Grid [I0-1] [J0] || Grid [I0-1] [J0 1] || CBLOCK.X <= 200) Return CBLOCK; CBLock.Shape ; Break; Case (4): IF (Grid [i0-1] [J0-2] || Grid [i0 1] [j0

1] RETURN CBLOCK; CBLOCK.Y- = 20; CBLock.x = 20; CBLock.Shape = 1; Break;} Break; Case ('Z'): Switch (CBLock.Shape) {CASE (1): IF (Grid [i0-1] [J0 1] || Grid [i0 1] [j0]) Return CBLOCK; CBLOCK.Y- = 20; CBLock.Shape ; Break; Case (2): IF (Grid [i0 2] || Grid [i0 2] [J0 2]) Return CBLOCK; CLOCK.Y = 20; CBLock.Shape- -; Break;} Break; Case ('n'): switch (cblock.shape) {case (1): if (Grid [i0] [j0] || Grid [i0-1] [j0]) Return CBLOCK; CLIAR_BLOCK (CBLOCK); CBLock.y- = 20; CBLock.Shape ; Break; Case (2): IF (Grid [I0 2] [J0] || Grid [i0 1] [J0 2] || CBLock .x> = 360) Return CBLOCK; CLOAR_BLOCK (CBLOCK); CBLock.y = 20; cblock.shape -; Break;} Break;} return cblock; / * Returns the converted square * /} / * Piece block function Transfer parameters for the current block instance variable * / void DrawBlock (struct block drblock) {Int I0, J0, I, J; J0 = (DRBLOCK.X-200) / 20; / * Put the square of the coordinate X, Y is converted into a corresponding array of Grid [I] [J] subscript I0, J0 * / I0 = (DRBLOCK.Y-40) / 20; SetFillStyle (9, DRBLOCK. Color; setColor (DRBLOCK.COLOR); Switch (DRBLOCK.TYPE) {CASE ('I'): if (DRBLOCK.SHAPE == 1) {for (j = 0; j <4; j ) {Rectangle (DRBLOCK .x J * 20, DRBLOCK.Y, DRBLOCK.X J * 20 20, DRBLOCK.Y 20); / * Painting Square * / FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y 10, DRBLOCK.COLOR); / * Spread Fill Square * / Grid [i0] [J0 J] = i_Shape1 [0] [J]; / * Put the defined shape with the Grid array * /} / * Things have a lattice corresponding GRID array element plus 1 * /} if (DRBLOCK.SHAPE == 2) {for (i = 0; i <4; i ) {Rectangle (DRBLOCK.X, DRBLOCK.Y 20 * i , DRBLOCK.X 20, DRBLOCK.Y 20 * I 20);

FLOODFILL (DRBLOCK.X 10, DRBLOCK.Y 20 * I 10, DRBLOCK.COLOR); Grid [i0 i] [j0] = i_shape2 [i] [0];}} Break; Case ('O '): for (i = 0; i <2; i ) for (j = 0; j <2; j ) {Rectangle (DRBLOCK.X i * 20, DRBLOCK.Y J * 20, DRBLOCK.X i * 20 20, drblock.y j * 20 20); floodfill (DRBLOCK.X I * 20 10, DRBLOCK.Y J * 20 10, DRBLOCK.COLOR); Grid [i0 i] [j0 j] = o_shape [i] [j];} Break; case ('t'): switch (drblock.shape) {case (1): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = t_shape1 [i] [j]; if (t_shape1 [i] [j] == 1) {Rectangle (DRBLOCK .x J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK. Y i * 20 10, DRBLOCK.COLOR);}} Break; case (2): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {grid [I0 i] [j0 j] = t_shape2 [i] [j]; if (t_shape2 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; CA SE (3): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = t_shape3 [i] [j] ; If (t_shape3 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; Case (4): for (i = 0; i <3; i

For (j = 0; j <2; j ) {grid [i0 i] [j0 j] = t_shape4 [i] [j]; if (t_shape4 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break;} Break; Case ('L'): Switch (DRBLOCK.SHAPE) {Case (1): for (i = 0; i <3 ; i ) for (j = 0; j <2; j ) {grid [i0 i] [j0 j] = l_shape1 [i] [j]; if (l_shape1 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; case (2): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {Grid [i0 i] [j0 j] = l_shape2 [i] [j]; if (l_shape2 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y i * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR );}} Break; Case (3): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {grid [i0 i] [j0 j] = l_shape3 [i] [j ]; If (l_shape3 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; Case (4): for (i = 0; i <2 i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = l_shape4 [i] [j]; if (l_shape4 [i] [j] ==

1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break;} Break; Case ('J'): Switch (DRBLOCK.SHAPE) {Case (1): for (i = 0 i <3; i ) for (j = 0; j <2; j ) {grid [i0 i] [j0 j] = j_shape1 [i] [j]; if (j_shape1 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; case (2): for (i = 0; i <2; i ) for (j = 0; J < 3; J ) {Grid [i0 i] [j0 j] = j_shape2 [i] [j]; if (j_shape2 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10 , DRBLOCK.COLOR);}} Break; Case (3): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {grid [i0 i] [j0 j ] = J_shape3 [i] [j]; if (j_shape3 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK. X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Case (4): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = j_shape4 [i] [j] ; If (j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20);

FLOODFILL (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break;} Break; Case ('Z'): Switch (DRBLOCK.SHAPE) {CASE 1): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = z_shape1 [i] [j]; if (Z_shape1 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20 ); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10, DRBLOCK.COLOR);}} Break; Case (2): for (i = 0; i <3; i ) For (j = 0; j <2; j ) {grid [i0 i] [j0 j] = z_shape2 [i] [j]; if (z_shape2 [i] [j] == 1) {Rectangle DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK .y i * 20 10, DRBLOCK.COLOR);}} Break;} Break; Case ('n'): switch (DRBLOCK.SHAPE) {Case (1): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {grid [i0 i] [j0 j] = n_shape1 [i] [j]; if (n_shape1 [i] [j] == 1) { Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); Floodfill (DRBLOCK.X J * 20 10, DRBLOCK.E I * 20 10, DRBLOCK.COLOR);}} Break; Case (2): for (i = 0; i <3; i ) for (j = 0; J < 2; J ) {Grid [i0 i] [j0 j] = n_shape2 [i] [j]; if (n_shape2 [i] [j] == 1) {Rectangle (DRBLOCK.X J * 20, DRBLOCK.Y I * 20, DRBLOCK.X J * 20 20, DRBLOCK.Y I * 20 20); FloodFill (DRBLOCK.X J * 20 10, DRBLOCK.Y I * 20 10 DRBLOCK.COLOR);

}}}}}}} / * Clear the original block, use the original container's checkered passing parameters for the current Block instance variable * / void clear_block (struct block cblock) {Int i, j, i0, j0; J0 = (CBLOCK.X-200) / 20; / * Convert the coordinate X, Y of the top left of the block into the corresponding array GRID [i] [j] subscript I0, J0 * / I0 = (CBLock.y- 40) / 20; setFillStyle (1, lightblue); / * Set the color of the fill color * / setColor (white); / * Restore the original foreground color * / switch (cBLock.Type) {CASE ('i '): if (cblock.shape == 1) {for (j = 0; j <4; j ) {Rectangle (CBLock.x J * 20, CBLock.y, CBLock.x J * 20 20, CBLOCK.Y 20); / * Sea original container plaid * / floodfill (CBLock.x J * 20 10, CBLock.y 10, White); / * Spread Fill * / Grid [I0] [J0 J] = 0; / * Clear, that is, the grid has no square * /}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} = 0; i <4; i ) {Rectangle .y 20 * i, cblock.x 20, CBLock.y 20 * i 20); floodfill (CBLOCK.X 10, CBLock.y 20 * i 10, white); Grid [i0 i ] [j0] = 0;}}} Break; Case ('o'): for (i = 0; i <2; i ) for (j = 0; j <2; j ) {Rectangle (CBLock.x i * 20, CBLOCK.Y J * 20, CBLOCK.X I * 20 20, CBLock.y J * 20 20); FloodFill (CBLock.x i * 20 10, CBLock.y J * 20 10, white); Grid [i0 i] [j0 j] = 0;} Break; Case ('t'): Switch ( CBLOCK.SHAPE) {case (1): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {IF (t_shape1 [i] [j] == 1) {Rectangle (CBLOCK.X J * 20, CBLOCK.Y I * 20, CBLock.x J * 20 20, CBLock.y i * 20 20); Floodfill (CBLock.x J * 20 10, CBLOCK.Y I * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break;

Case (2): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {ix (t_shape2 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLOCK.Y I * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); FloodFill (CBLock.x J * 20 10, CBLock.y i * 20 10, white); Grid [i0 i] [j0 j] = 0;}} Break; case (3): for (i = 0; i <2; i ) for (j = 0; J <3; J ) {IF (t_shape3 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLock.x J * 20 20, CBLOCK. Y i * 20 20); floodfill (CBLock.x J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break; case (4): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {if (t_shape4 [i] [j] == 1) {Rectangle (CBLOCK. X J * 20, CBLOCK.Y I * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); FloodFill (CBLock.x J * 20 10, CBLock.y i * 20 10, white); Grid [i0 i] [j0 j] = 0;}} Break;} Break; case ('l'): switch (cblock.shape) {case (1): For (i = 0; i <3; i ) for (j = 0; j <2; j ) {if (l_shape1 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLOCK .y i * 20, CBLOCK.X J * 20 20, CBLOCK.Y I * 20 20); FLO ODFILL (CBLOCK.X J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break; Case (2): for i = 0; i <2; i ) for (j = 0; j <3; j ) {if (l_shape2 [i] [j] == 1) {Rectangle (CBLock.x j * 20, cblock.y i * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); floodfill (CBLock.x J * 20 10, CBLock.y i * 20

10, white); Grid [i0 i] [j0 j] = 0;}}} Break; case (3): for (i = 0; i <3; i ) for (j = 0; J <2; J ) {if (l_shape3 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLock.y i * 20, CBLock.x J * 20 20, CBLOCK.Y i * 20 20); floodfill (CBLOCK.X J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break; Case (4): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {if (l_shape4 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLOCK.Y I * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); floodfill (CBLock.x J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break;} Break; case ('J'): switch (cblock.shape) {case (1): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {if (j_shape1 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLock.y i * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); floodfill (CBLock.x J * 20 10, CBLOCK.Y I * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break; case (2): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {IF ( J_Shape2 [i] [j] == 1) {Rectangle (CBL Ock.x J * 20, CBLock.y i * 20, CBLock.x J * 20 20, CBLock.y i * 20 20); FloodFill (CBLOCK.X J * 20 10, CBLOCK .y i * 20 10, white); Grid [i0 i] [j0 j] = 0;}} Break; case (3): for (i = 0; i <3; i ) for (J = 0; j <2; j ) {IF (j_shape3 [i] [j] == 1) {Rectangle (CBLOCK.X J * 20, CBLOCK.Y I * 20, CBLock.x J * 20 20, CBLOCK.Y

I * 20 20); floodfill (CBLock.x J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Case (4): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {ix (j_shape4 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLOCK.Y I * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); FloodFill (CBLock.x J * 20 10, CBLock.y i * 20 10, white); Grid [i0 i] [j0 j] = 0;}} Break;} Break; case ('z'): switch (cblock.shape) {case (1): for i = 0; i <2; i ) for (j = 0; j <3; j ) {if (z_shape1 [i] [j] == 1) {Rectangle (CBLock.x j * 20, cblock.y i * 20, CBLOCK.X J * 20 20, CBLOCK.Y I * 20 20); FloodFill (CBLock.x J * 20 10, CBLock.y i * 20 10, White) ; Grid [i0 i] [j0 j] = 0;}} Break; case (2): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {IF (Z_shape2 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLock.x J * 20 20, CBLock.y i * 20 20 ); Floodfill (CBLOCK.X J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break;} Break; Case 'N'): switch (cblock.shape) {casse (1): For (i = 0; i <2; i ) for (j = 0; j <3; j ) {if (n_shape1 [i] [j] == 1) {Rectangle (CBLock.x J * 20, CBLOCK .y i * 20, CBLOCK.X J * 20 20, CBLock.y i * 20 20); floodfill (CBLock.x J * 20 10, CBLock.y i * 20 10, White); Grid [I0 I] [J0 J] = 0;}}}}} Break; Case (2): for (i = 0; i <3; i ) for (j = 0; j <2; J )

) {If (n_shape2 [i] [j] == 1) {Rectangle (CBLock.x j * 20, CBLock.y i * 20, CBLock.x J * 20 20, CBLock.y i * 20 20); floodfill (CBLOCK.X J * 20 10, CBLock.y i * 20 10, White); Grid [i0 i] [j0 j] = 0;}} Break;} BREAK }} / * The judgment is the top of the container. It is also the game end sign. If the top is returned 1, otherwise returns 0 * / int check_top (struct block tblock) {if (tblock.y == 40) Return 1; Else Return 0;} / * Decision whether the square is in the bottom of the container or there is some other squares, and there is a return 1, otherwise returns 0 * / int check_bottom (struct block nblock) {Int J, I0, J0; J0 = (nblock.x -200) / 20; I0 = (nblock.y-40) / 20; switch (nblock.Type) {case ('i'): if (nblock.shape == 1) {if (nblock.y == 420 RETURN 1; / * has arrived at the bottom * / for (j = 0; j <4; j ) IF (Grid [i0 1] [j0 j]) Return 1; / * i-shaped block under one Static square * /} if (nblock.shape == 2) {if (nblock.y == 360) Return 1; if (Grid [i0 4] [j0]) return 1;} Break; Case ('O '): if (nblock.y == 400) Return 1; for (j = 0; j <2; j ) IF (Grid [i0 2] [J0 J]) Return 1; Break; Case (' T '): Switch (nblock.shape) {case (1): if (nblock.y == 400) Return 1; if (Grid [i0 2] [j0 1] || Grid [i0 1] [J0 ] | | Grid [I0 1] [J0 2]) Return 1; Break; Case (2): if (nblock.y == 380) Return 1; IF (Grid [I0 3] [J0 1] || Grid [i0 2] [j0]) RETURN 1; Break; case (3): if (nblock.y == 400) Return 1; for (j = 0; j <3; j ) IF (Grid [I0 2] [J0 J]) Return 1; Break; Case (4): if (nblock.y == 380) Return 1; IF (Grid [i0 3] [J0] || Grid [i0 2] [ J0 1]) RETURN 1; Break;} Break; Case ('L'

: switch (nblock.shape) {case (1): if (nblock.y> = 380) Return 1; if (Grid [i0 3] [j0] || Grid [i0 3] [J0 1] ) RETURN 1; Break; case (2): if (nblock.y> = 400) Return 1; if (Grid [i0 2] [j0] || Grid [i0 1] [J0 1] || Grid [I0 1] [J0 2]) Return 1; Break; Case (3): if (nblock.y> = 380) Return 1; IF (Grid [I0 3] [J0 1] || Grid [ I0 1] [j0]) RETURN 1; Break; Case (4): if (nblock.y> = 400) Return 1; for (j = 0; j <3; j ) IF (Grid [I0 2] [J0 J]) Return 1; Break;} Break; Case ('J'): switch (nblock.shape) {case (1): if (nblock.y> = 380) Return 1; IF (Grid [I0 3] [J0] || Grid [i0 3] [J0 1]) Return 1; Break; Case (2): if (nblock.y> = 400) Return 1; for (j = 0; J < 3; J ) IF (GRID [I0 2]) Return 1; Break; Case (3): if (nblock.y> = 380) Return 1; IF (Grid [I0 3] [J0 ] || Grid [I0 1] [J0 1]) Return 1; Break;

Case (4): if (nblock.y> = 400) Return 1; IF (Grid [i0 2] [J0 2] || Grid [i0 1] [j0] || grid [i0 1] [ J0 1]) RETURN 1; Break;} Break; case ('z'): if (nblock.shape == 1) {if (nblock.y == 400) Return 1; if (Grid [i0 1] [J0] || Grid [i0 2] [J0 1] || Grid [I0 2] [J0 2]) Return 1;}}}}}}}}}}}}}}} If (nblock.shape == 2) {if (nblock.y = = 380) RETURN 1; IF (Grid [I0 3] [J0] || Grid [i0 2] [J0 1]) Return 1;} Break; Case ('n'): if (nblock.shape = = 1) {if (nblock.y == 400) Return 1; if (Grid [i0 1] [j0 2] || Grid [i0 2] [j0 1] || Grid [i0 2] [j0]) RETURN 1;}}} (nblock.shape == 2) {if (nblock.y == 380) Return 1; if (Grid [i0 2] [j0] || grid [i0 3] [ J0 1]) Return 1;} Break

} RETURN 0;} / * Display the next block of the next block * / void show_next (struct block nextblock) {INT I, J, G [4] [4]; setFillStyle (1, lightblue); setColor (White ); for (i = 0; i <4; i ) for (j = 0; j <4; j ) {Rectangle (480 i * 20, 40 j * 20, 480 i * 20 20, 40 J * 20 20); floodfill (480 i * 20 10, 40 20 * J 10, White);} setfillstyle (9, nextblock.color); setColor (NextBlock.color); Switch (NextBlock.Type) {Case ('I'): for (j = 0; j <4; j ) {Rectangle (480 J * 20, 60, 480 J * 20 20, 60 20); floodfill (480 J * 20 10, 60 10, NextBlock.color;} Break; Case ('o'): for (i = 0; i <2; i ) for (j = 0; j <2; j ) {Rectangle (500 20 * I, 60 20 * J, 500 20 * i 20, 60 20 * J 20); Floodfill (500 20 * i 10, 60 20 * J 10, NextBlock.color); } Break; Case ('t'): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {g [i] [j] = t_shape1 [i] [j] ; If (g [i] [j] == 1) {Rectangle (480 j * 20, 60 i * 20, 480 j * 20 20, 60 i * 20 20); floodfill (480 j * 20 10, 60 i * 20 10, NextBlock.color);}} Break; Case ('L'): for (i = 0; i <3; i ) for (j = 0; J <2; J ) {g [i] [j] = l_shape1 [i] [j]; if (g [i] [j] == 1) {RECTA NGLE (500 J * 20, 40 i * 20, 500 J * 20 20, 40 i * 20 20); Floodfill (500 J * 20 10, 40 i * 20 10, NextBlock.color Break;

Case ('j'): for (i = 0; i <3; i ) for (j = 0; j <2; j ) {g [i] [j] = j_shape1 [i] [j]; if g [i] [j] == 1) {Rectangle (500 J * 20, 40 i * 20, 500 j * 20 20, 40 i * 20 20); floodfill (500 j * 20 10 40 i * 20 10, nextblock.color;}}}}} Break; Case ('Z'): for (i = 0; i <2; i ) for (j = 0; j <3; j ) { g [i] [j] = z_shape1 [i] [j]; if (g [i] [j] == 1) {Rectangle (500 J * 20, 60 i * 20, 500 j * 20 20, 60 i * 20 20); floodfill (500 j * 20 10, 60 i * 20 10, nextblock.color);}}} Break; Case ('n'): for (i = 0; i <2; i ) for (j = 0; j <3; j ) {g [i] [j] = n_shape1 [i] [j]; if (g [i] [j] == 1) {Rectangle 500 J * 20, 60 I * 20, 500 J * 20 20, 60 i * 20 20); Floodfill (500 J * 20 10, 60 i * 20 10, NextBlock.color); }}} Break;}} / * Test the grid array's value * / void test () {INT I, J; gotoxy (1, 1); for (i = 0; i <20; i ) {for (j = 0 ; J <10; J ) Printf ("% 2D", Grid [i] [j]); printf ("/ n");}}

/ * Initial the graphic driver * / int ini_graph (void) {/ * request auto detection * / int gDriver = detect, gmode, erroorcode; int LEFT, TOP, RIGHT, BOTTOM

/ * Initialize Graphics and local variables * / initgraph (& gdriver, & gmode, "");

/ * read results = graphresult (); if (error (error) / * an error opcurred * / {printf ("Graphics Error:% S / N", GrapherrorMSG (ErrorCode)); Printf (" Press any key to halt: "); getCH (); exit (1); / * Terminate with an error code * /}

Return 0;

} / * show the game information on right * / void help (int xs, int ys) {setColor (15); Rectangle (XS-3, YS-3, XS 200, YS 150); LINE (XS-3 , YS 26, XS 200, YS 26); LINE (XS-3, YS 72, XS 200, YS 72); LINE (XS 39, YS 26, XS 39, YS 72 ); SetColor (12); OUTTEXTXY (XS 60, YS 8, "Welcome !!"); setColor (14); Outtextxy (xs, ys 45, "help:"); OutTextxy (xs 55, ys 30, "-> - left; <- right"); Outtextxy (xs 55, ys 45, "^ - change"); Outtextxy (xs 55, ys 60, "ESC-EXIT; R- "); OUTTEXTXY (XS, YS 75," Russia Diamonds "); OUTTEXTXY (XS, YS 90," Copyright by Fanz.com "); Outtextxy (XS, YS 105," Date: 15/12 / "); OUTTEXTXY (XS, YS 120," E-mail: fanz@263.net ");} / * show score and level * / void showscore () {int Cur [8]; CUR [0] = 420; CUR [1] = 360; CUR [2] = CUR [0]; CUR [3] = CUR [1] 50; CUR [4] = CUR [2] 203; CUR [5] = CUR [ 3]; CUR [6] = CUR [4]; CUR [7] = CUR [5] -50; setColor (LightBlue); SetFillStyle (7, lightblue);

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

New Post(0)