The main code for rewriting a Tetris is 3 ~ It takes a long time for the Study of Automatic whereabouts to be completed in four hours .... But now I can look back at the Russian box I wrote before .... Compiled in VC ++ 6.0
# Include <iostream> <br/> # include <conio. h> <br/> # include <windows. h> <br/> # include <time. h> <br/> # pragma comment (lib, "winmm. lib ") <br/> using namespace std; <br/> # define MAPSIZEH 20 <br/> # define MAPSIZEL 15 </p> <p>/* <br/> operation: the upper and lower left wsad space is a speed drop <br/> */<br/> char GRA [24] [4] [4] = <br/>{< br/> {0, 0, ,},/* field lattice */<br/> {, 0, 0, 0, 0},/* horizontal */<br/> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},/* vertical */<br/> }, /* Top Soil */<br/> {0, 0, 0, 0, 0, 0, 0, 0 }, /* Right Earth */<br/> {0, 0, 0, 0, 0, 0, 0},/* bottom earth */<br/> {0, 0, 0, 0, 0, 0, 0, 0},/* left soil */<br/> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },/* Z */<br/> }, /* Z */<br/> {, 0,},/* Z */<br/>,, 0, 0,/* Z */<br/>, ,},/*-| */<Br/> {, 0 }, /* __| */<br/> {0, 0, 0, 0, 0, 0, 0 }, /* | _ */<br/> {0, 0, 0, 0, 0, 0, 0 }, /* | -- */<br/> {0, 0, 0, 0, 0, 0 }, /* |-*/<br/> }, /* -- | */<br/> {, 0 }, /* _ | */<br/> {0, 0, 0, 0, 0, 0 }, /* |__ */<br/> {0, 0, 0,},/* Super dashboard */ <Br/> {,},/* Large Vertical */<br/> {0, 0, 0, 0, ,},/* Large Horizontal */<br/> }, /* 10 */<br/> {,},/* hollow dashboard */<br/> }; <br/> char MAP [MAPSIZEH] [MAPSIZEL]; int STARTX, STARTY/* Start XY coordinate */, TYPE/* Current graph TYPE */, NEXTTYPE/* next graph */, SOCER/* Current score */, TURN [24] =, 15, 19,};/* rotate status jump */</p> <p> struct Move <br/> {<br/> int x, y; <br/>} move [4] = {0,-, 0 }; /* determines whether the square can be rotated if it is left and right and does not move. */</p> <p> bool decidemove (int type, int dis) /* determine whether the square can be moved or rotated */<br/> {<br/> int I, j; <br/> for (I = 0; I <4; I ++) <br/> for (j = 0; j <4; j ++) <br/> if (GRA [type] [I] [j]) <br/> {<br/> if (STARTX + I + move [dis]. x <0 | STARTX + I + move [dis]. x> = MAPSIZEH | STARTY + j + move [dis]. y <0 | STARTY + j + move [dis]. y> = MAPSIZEL | MAP [STARTX + I + move [dis]. x] [STARTY + j + move [d Is]. y] = 1) <br/> return false; <br/>}< br/> return true; <br/>}</p> <p> void lockinmap (int s)/* fix the block on the map */<br/> {<br/> int I, j; <br/> for (I = 0; I <4; I ++) <br/> for (j = 0; j <4; j ++) <br/> if (GRA [TYPE] [I] [j]) <br/> MAP [STARTX + I] [STARTY + j] = s; <br/>}</p> <p> void moving (int type, int dis) /* move the square on the screen */<br/> {<br/> int I, j; <br/> lockinmap (0 ); /* Set '2' in MAP to 0 */</p> <p> STARTX + = move [dis]. x; STARTY + = move [dis]. y;/* move the square */<br/> loc Kinmap (2); </p> <p >}</p> <p> void gotoxy (int x, int y) /* move the cursor */<br/> {<br/> coord c; <br/> C.X = x; <br/> C. Y = y; <br/> SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), C); <br/>}</p> <p> void show () /* display screen */<br/> {<br/> gotoxy (); <br/> int I, j; <br/> for (I = 0; I <MAPSIZEH; I ++, cout <endl) <br/> for (j = 0; j <MAPSIZEL; j ++) <br/> if (MAP [I] [j]) <br/> cout <"■"; <br/> else <br/> cout <""; <br/> gotoxy (MAPSIZEL * 2 + 4, 2 ); <Br/> for (I = 0; I <4; I ++, gotoxy (MAPSIZEL * 2 + 4, 2 + I )) <br/> for (j = 0; j <4; j ++) <br/> if (GRA [NEXTTYPE] [I] [j]) <br/> cout <"■"; <br/> else <br/> cout <""; </p> <p> gotoxy (MAPSIZEL * 2 + 4, 2 + 10); <br/> cout <"SCORE "; <br/> gotoxy (MAPSIZEL * 2 + 4, 2 + 12); <br/> cout <"" <SOCER; <br/> gotoxy (MAPSIZEL * 3 + 1, MAPSIZEH); <br/>}</p> <p> void creat ()/* generate random squares */<br/>{< br/> STARTX = 0; STARTY = MAPSIZEL/2-1; <br/> TYPE = NEXTTYPE; <br/> srand (u Nsigned) time (NULL); <br/> NEXTTYPE = rand (); <br/> if (NEXTTYPE <0) <br/> NEXTTYPE * =-1; <br/> NEXTTYPE % = 24;/* generate a random number */<br/> if (TYPE <0) <br/> TYPE * =-1; <br/> TYPE % = 24; <br/> if (decidemove (TYPE, 3) = false) <br/>{< br/> system ("cls"); <br/> cout <"game end" <endl <"your socer is "; <br/> PlaySound ("end.wav", NULL, SND_ALIAS | SND_ASYNC); <br/> Sleep (2000); <br/> cout <SOCER <endl; <br/> KillTimer (NULL, 1); <br/> system ("pau Se "); <br/> exit (0); <br/>}< br/> moving (TYPE, 3 ); <br/>}</p> <p> void check ()/* function for determining the elimination and Division */<br/> {<br/> int I, j, res = 0, sum; <br/> for (I = MAPSIZEH-1; I>-1; I --) <br/> {<br/> for (j = MAPSIZEL-1, sum = 0; j>-1; j --) <br/> sum + = MAP [I] [j]; <br/> if (sum = MAPSIZEL) /* if a full row is found, delete the line */<br/>{< br/> res ++; <br/> int k = I, s; <br/> for (; k> 0; k --) <br/> for (s = 0; s <MAPSIZEL; s ++) <br/> MAP [k] [s] = MAP [k-1] [s]; <br/> memset (MAP, 0, sizeof (char) * MAPSIZ EL); <br/> I ++; <br/>}< br/> if (res) <br/> PlaySound ("AK47A.wav ", NULL, SND_ALIAS | SND_ASYNC); <br/> else <br/> PlaySound ("oned.wav", NULL, SND_ALIAS | SND_ASYNC ); <br/> SOCER + = 100 * res;/* calculate the consumption score */<br/>}</p> <p> void OnTime () /* callback function */<br/> {</p> <p> if (true = decidemove (TYPE, 2) <br/> {moving (TYPE, 2) ;}< br/> else <br/>{< br/> lockinmap (1); <br/> check (); <br/> creat (); <br/>}< br/> show (); <br/>}</p> <p> void ope Rate ()/* Control Box movement function */<br/> {<br/> char op; int s = 0; <br/> while (s! = 100) <br/>{< br/> if (kbhit ()) /* skipped if no operation exists */<br/>{< br/> op = getch (); <br/> if (op = 'A' | op = 'A') <br/> {<br/> if (true = decidemove (TYPE, 0) <br/> {moving (TYPE, 0); show ();} </p> <p >}< br/> elseif (op = 'D' | op = 'D ') <br/>{< br/> if (true = decidemove (TYPE, 1) <br/> {moving (TYPE, 1); show ();} <br/>}< br/> else if (op = 'W' | op = 'W ') <br/>{< br/> if (decidemove (TURN [TYPE], 3) = true) <br/>{< br/> lockinmap (0 ); <br/> TYPE = TURN [TYPE]; <br/> moving (TYPE, 3); <br/> show (); <br/> PlaySound ("sound1.wav ", NULL, SND_ALIAS | SND_ASYNC); <br/>}< br/> elseif (op = 's' | op ='s ') <br/>{< br/> if (true = decidemove (TYPE, 2) <br/> moving (TYPE, 2 ); <br/> else <br/> {<br/> lockinmap (1); <br/> check (); <br/> creat (); <br/>}< br/> show (); <br/>}< br/> else if (op = 0x20) <br/>{< br/> while (true = decidemove (TYPE, 2) <br/> moving (TYPE, 2 ); <br/> lockinmap (1); <br/> check (); <br/> creat (); <br/> show (); <br/>}< br/> s ++; <br/> Sleep (2); <br/>}< br/> OnTime (); <br/>}</p> <p> void first ()/* initialization interface */<br/> {<br/> memset (MAP, 0, sizeof (MAP); <br/> SOCER = 0; <br/> srand (unsigned) time (NULL); <br/> NEXTTYPE = rand (); <br/> if (NEXTTYPE <0) <br/> NEXTTYPE * =-1; <br/> NEXTTYPE % = 24; <br/> creat (); <br/> show (); <br/> int I; <br/> for (I = 0; I <MAPSIZEH; I ++) <br/> {gotoxy (MAPSIZEL * 2, I); cout <"plugin"; gotoxy (MAPSIZEL * 3, I); cout <"plugin ";} <br/> gotoxy (0, MAPSIZEH); <br/> for (I = 0; I <MAPSIZEL * 1.5; I ++) <br/> cout <"success"; </p> <p >}</p> <p> int main () <br/> {<br/> first ();/* initialization interface */<br/> while (1) /* enter the game */<br/> operate (); </p> <p> return 0; <br/>}</p> <p>