@[TOC]

I. Game effects

The old version is 800 lines of code, this one is 500 lines, and it doesn’t flash, so it looks comfortable. Without further ado, above, code.

Two. Code implementation

1. Map

void DeawMap(a)
{
 for (int i = 0; i < WIDTH; i++)PRINTF LINE  / / on the border
  for (int i = 1; i < HEIGHT - 1; i++)          // Prints the left and right borders
  {
   for (int j = 0; j < WIDTH; j++)
   {
    if (j == 0 || j == WIDTH - 1)
    {
     PRINTF
      if (j == WIDTH - 1)LINE
    }
    else EMPTY
   }
  }
 for (int i = 0; i < WIDTH; i++)PRINTF LINE  / / bottom border
  system("color 03");
}
Copy the code

2. Random main block generation

Tetris * BlockRand(int code_y)
{
 srand((int)time(0));
 Tetris * Block = (Tetris*)malloc(sizeof(Tetris));
 Block->x_1 = 8;
 Block->y_1 = 4;// set the coordinates of the initial center block to (8,4).
 Block->code = code_y;
 if (Phead == NULL)Phead = Block;
 else Pend->next = Block;
 Block->next = NULL;
 Pend = Block;
 return Block;
}
Copy the code

3. Key response

void JudgeDirection(Tetris ** Block)
{
 if (GetAsyncKeyState(VK_UP) && 0x8000)
 {
  form += 1;
  if (form == 4)
  {
   form = 0;
  }
  Form(&Return);
 }
 if (GetAsyncKeyState(VK_DOWN) && 0x8000)
 {
  // Accelerate down time
  UP = 1;
 }
 if (GetAsyncKeyState(VK_LEFT) && 0x8000)
 {
  // Move left
  if(JudgeWall(&Return) ! =- 1) Location_y(&Return, - 1.0.- 1.0.- 1.0.- 1.0);
 }
 if (GetAsyncKeyState(VK_RIGHT) && 0x8000)
 {
  // Move to the right
  if(JudgeWall(&Return) ! =2 -) Location_y(&Return, 1.0.1.0.1.0.1.0);
 }
 if (GetAsyncKeyState(VK_ESCAPE) && 0x0D)
 {
  MoveCursor(27.15);
  printf("Game pause");
  //判断Esc
  while (1)
  {
   if (GetAsyncKeyState(VK_ESCAPE) && 0x0D)
   {
    MoveCursor(27.15);
    printf("");
    break; }}}}Copy the code

4. Block coordinates are all confirmed

void Form(Tetris ** Block)
{
 // Determine which category first, then subdivide
 switch ((*Block)->code)
 {
 case 1:
  if (form == 0)Location(&Return, 0.0.- 1.0.0.- 1.1.0);
  if (form == 1)Location(&Return, 0.0.0.1.0.- 1.1.0);
  if (form == 2)Location(&Return, 0.0.0.1.- 1.0.1.0);
  if (form == 3)Location(&Return, 0.0.0.1.- 1.0.0.- 1);
  break;
 case 2:
  Location(&Return, 0.0.1.0.0.1.1.1);
  break;
 case 3:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.- 1.0.1.0.2);
  if (form == 1 || form == 3)Location(&Return, 0.0.- 1.0.1.0.2.0);
  break;
 case 4:
  if (form == 0)Location(&Return, 0.0.- 1.0.1.0.1.- 1);
  if (form == 1)Location(&Return, 0.0.0.- 1.1.0.0.2 -);
  if (form == 2)Location(&Return, 0.0.0.- 1.1.- 1.2.- 1);
  if (form == 3)Location(&Return, 0.0.0.- 1.0.2 -.- 1.2 -);
  break;
 case 5:
  if (form == 0)Location(&Return, 0.0.1.0.2.0.0.- 1);
  if (form == 1)Location(&Return, 0.0.1.0.1.- 1.1.2 -);
  if (form == 2)Location(&Return, 0.0.1.0.2.0.2.1);
  if (form == 3)Location(&Return, 0.0.1.0.0.1.0.2);
  break;
 case 6:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.- 1.1.0.1.1);
  if (form == 1 || form == 3)Location(&Return, 0.0.0.- 1.1.- 1.- 1.0);
  break;
 case 7:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.1.1.0.1.- 1);
  if (form == 1 || form == 3)Location(&Return, 0.0.0.1.- 1.0.1.1); }}Copy the code

5. Display the complete block

void ShowBlock(Tetris ** Block)
{
 while (1)
 {
  Form(&Return);
  if ((*Block)->code == 1)SetColour(13);
  if ((*Block)->code == 2)SetColour(15);
  if ((*Block)->code == 3)SetColour(12);
  if ((*Block)->code == 4)SetColour(10);
  if ((*Block)->code == 5)SetColour(6);
  if ((*Block)->code == 6)SetColour(4);
  if ((*Block)->code == 7)SetColour(8);
  MoveCursor((*Block)->x_1, (*Block)->y_1); PRINTF
   MoveCursor((*Block)->x_2, (*Block)->y_2); PRINTF
   MoveCursor((*Block)->x_3, (*Block)->y_3); PRINTF
   MoveCursor((*Block)->x_4, (*Block)->y_4); PRINTF
   if (JudgeGroud(Phead, &Return) == 0)
   {
    system("color 03");
    break;
   }
  if (UP == 0)
  {
   for (int i = 0; i <= 400000000; i++) {}
  }
  if (UP == 1)
  {
   for (int i = 0; i <= 40000000; i++) {}
   UP = 0;
  }
  MoveCursor((*Block)->x_1, (*Block)->y_1); EMPTY
   MoveCursor((*Block)->x_2, (*Block)->y_2); EMPTY
   MoveCursor((*Block)->x_3, (*Block)->y_3); EMPTY
   MoveCursor((*Block)->x_4, (*Block)->y_4); EMPTY
   Location_y(&Return, 0.1.0.1.0.1.0.1); JudgeDirection(&Return); JudgeEntire(Phead); }}Copy the code

6. Determine boundaries

int JudgeWall(Tetris ** Block)
{
 if ((*Block)->x_1 == ZERO || (*Block)->x_2 == ZERO || (*Block)->x_3 == ZERO || (*Block)->x_4 == ZERO)return - 1;
 if ((*Block)->x_1 == HEIGHT_1 || (*Block)->x_2 == HEIGHT_1 || (*Block)->x_3 == HEIGHT_1 || (*Block)->x_4 == HEIGHT_1)return 2 -;
 return 0;
}
Copy the code

7. Move the cursor

void MoveCursor(int x, int y)// Set the cursor position (that is, the start of the output display)
{
 COORD pos = { x * 2,y };
 HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);// Get a handle to the standard output
 SetConsoleCursorPosition(output, pos); // Set the console cursor position
}
Copy the code

8. Color Settings

void SetColour(int c)
{
 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);// The API function can change the console color
}
Copy the code

9. Judge landing

int JudgeGroud(Tetris * Phead, Tetris ** Block)
{
 Tetris * P = Phead;
 // If you reach the lowest level. Go straight through the next loop
 if ((*Block)->y_1 == 26 || (*Block)->y_2 == 26 || (*Block)->y_3 == 26 || (*Block)->y_4 == 26)return 0;
 while(P->next ! =NULL)
 {
  if (P->y_1 == (*Block)->y_1 + 1)
  {
   if (P->x_1 == (*Block)->x_1)return 0;
  }
  if (P->y_2 == (*Block)->y_1 + 1)
  {
   if (P->x_2 == (*Block)->x_1)return 0;
  }
  if (P->y_3 == (*Block)->y_1 + 1)
  {
   if (P->x_3 == (*Block)->x_1)return 0;
  }
  if (P->y_4 == (*Block)->y_1 + 1)
  {
   if (P->x_4 == (*Block)->x_1)return 0;
  }
  if (P->y_1 == (*Block)->y_2 + 1)
  {
   if (P->x_1 == (*Block)->x_2)return 0;
  }
  if (P->y_2 == (*Block)->y_2 + 1)
  {
   if (P->x_2 == (*Block)->x_2)return 0;
  }
  if (P->y_3 == (*Block)->y_2 + 1)
  {
   if (P->x_3 == (*Block)->x_2)return 0;
  }
  if (P->y_4 == (*Block)->y_2 + 1)
  {
   if (P->x_4 == (*Block)->x_2)return 0;
  }
  if (P->y_1 == (*Block)->y_3 + 1)
  {
   if (P->x_1 == (*Block)->x_3)return 0;
  }
  if (P->y_2 == (*Block)->y_3 + 1)
  {
   if (P->x_2 == (*Block)->x_3)return 0;
  }
  if (P->y_3 == (*Block)->y_3 + 1)
  {
   if (P->x_3 == (*Block)->x_3)return 0;
  }
  if (P->y_4 == (*Block)->y_3 + 1)
  {
   if (P->x_4 == (*Block)->x_3)return 0;
  }
  if (P->y_1 == (*Block)->y_4 + 1)
  {
   if (P->x_1 == (*Block)->x_4)return 0;
  }
  if (P->y_2 == (*Block)->y_4 + 1)
  {
   if (P->x_2 == (*Block)->x_4)return 0;
  }
  if (P->y_3 == (*Block)->y_4 + 1)
  {
   if (P->x_3 == (*Block)->x_4)return 0;
  }
  if (P->y_4 == (*Block)->y_4 + 1)
  {
   if (P->x_4 == (*Block)->x_4)return 0;
  }
  P = P->next;
 }
 return 1;
}
Copy the code

10. Determine if the entire line is filled

void JudgeEntire(Tetris * Head)
{
 Tetris * PHead = Head;
 // From 1 to 26
 for (int y = 26; y >= 1; y--)
 {
  int sum = 0;
  while(PHead->next ! =NULL)
  {
   if (PHead->y_1 == y)sum++;
   if (PHead->y_2 == y)sum++;
   if (PHead->y_3 == y)sum++;
   if (PHead->y_4 == y)sum++;
   MoveCursor(20.28);
   PHead = PHead->next;
  }
  PHead = Head;
  if (sum == 18)
  {
   // If there is a line, execute NewEntire() to empty the line and drop all y by one unit.
   NewEntire(Phead, y);
   fengs += 10;
   Show(code_y);
  }
  sum = 0; }}Copy the code

11. If filled, clear the line and refresh the map

void NewEntire(Tetris * head, int y)
{
 Tetris * PHead = head;
 while(PHead->next ! =NULL)
 {
  if (PHead->y_1 == y)
  {
   MoveCursor(PHead->x_1, PHead->y_1); EMPTY
    PHead->x_1 = 99;
   PHead->y_1 = 99;
  }
  if (PHead->y_2 == y)
  {
   MoveCursor(PHead->x_2, PHead->y_2); EMPTY
    PHead->x_2 = 99;
   PHead->y_2 = 99;
  }
  if (PHead->y_3 == y)
  {
   MoveCursor(PHead->x_3, PHead->y_3); EMPTY
    PHead->x_3 = 99;
   PHead->y_3 = 99;
  }
  if (PHead->y_4 == y)
  {
   MoveCursor(PHead->x_4, PHead->y_4); EMPTY
    PHead->x_4 = 99;
   PHead->y_4 = 99;
  }
  PHead = PHead->next;
 }
 PHead = head;
 while(PHead->next ! =NULL)
 {
  if (PHead->y_1 < y)
  {
   MoveCursor(PHead->x_1, PHead->y_1); EMPTY
    PHead->y_1 += 1;
   MoveCursor(PHead->x_1, PHead->y_1); PRINTF
  }
  if (PHead->y_2 < y)
  {
   MoveCursor(PHead->x_2, PHead->y_2); EMPTY
    PHead->y_2 += 1;
   MoveCursor(PHead->x_2, PHead->y_2); PRINTF
  }
  if (PHead->y_3 < y)
  {
   MoveCursor(PHead->x_3, PHead->y_3); EMPTY
    PHead->y_3 += 1;
   MoveCursor(PHead->x_3, PHead->y_3); PRINTF
  }
  if (PHead->y_4 < y)
  {
   MoveCursor(PHead->x_4, PHead->y_4); EMPTY
    PHead->y_4 += 1; MoveCursor(PHead->x_4, PHead->y_4); PRINTF } PHead = PHead->next; }}Copy the code

12. Display information

void Show(int n)
{
 // Display the next square
 // Clear the area first
 for (int j = 4; j <= 8; j++)
 {
  for (int i = 23; i <= 28; i++)
  {
   MoveCursor(i, j);  EMPTY
  }
 }
 MoveCursor(24.3);
 printf("Next block type:");
 MoveCursor(24.10);
 printf("Game score: % D", fengs);
 MoveCursor(24.12);
 printf("Made by Fdog, it's a must.");
 if (n == 1)
 {
  SetColour(13);
  Location_x(- 1.0.0.0.1.0.- 1.- 1);
 }
 if (n == 2)
 {
  SetColour(15);
  Location_x(0.0.1.0.- 1.1.1.1);
 }
 if (n == 3)
 {
  SetColour(12);
  Location_x(0.0.1.0.2.0.3.0);
 }
 if (n == 4)
 {
  SetColour(10);
  Location_x(0.0.1.0.2.0.2.- 1);
 }
 if (n == 5)
 {
  SetColour(6);
  Location_x(0.- 1.0.0.1.0.2.0);
 }
 if (n == 6)
 {
  SetColour(4);
  Location_x(- 1.- 1.- 1.0.0.0.0.1);
 }
 if (n == 7)
 {
  SetColour(8);
  Location_x(0.- 1.0.0.- 1.0.- 1.1); }}Copy the code

13. Coordinate update 1

void Location(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f)
{
 (*Block)->x_1 = (*Block)->x_1 + x;
 (*Block)->y_1 = (*Block)->y_1 + y;
 (*Block)->x_2 = (*Block)->x_1 + a;
 (*Block)->y_2 = (*Block)->y_1 + b;
 (*Block)->x_3 = (*Block)->x_1 + c;
 (*Block)->y_3 = (*Block)->y_1 + d;
 (*Block)->x_4 = (*Block)->x_1 + e;
 (*Block)->y_4 = (*Block)->y_1 + f;
}
Copy the code

14. Coordinate Update 2

void Location_y(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f)
{
 (*Block)->x_1 = (*Block)->x_1 + x;
 (*Block)->y_1 = (*Block)->y_1 + y;
 (*Block)->x_2 = (*Block)->x_2 + a;
 (*Block)->y_2 = (*Block)->y_2 + b;
 (*Block)->x_3 = (*Block)->x_3 + c;
 (*Block)->y_3 = (*Block)->y_3 + d;
 (*Block)->x_4 = (*Block)->x_4 + e;
 (*Block)->y_4 = (*Block)->y_4 + f;
}
Copy the code

15. Information is updated

void Location_x(int x, int y, int a, int b, int c, int d, int e, int f)
{
 MoveCursor(Loca_x + x, Loca_y + y); PRINTF
  MoveCursor(Loca_x + a, Loca_y + b); PRINTF
  MoveCursor(Loca_x + c, Loca_y + d); PRINTF
  MoveCursor(Loca_x + e, Loca_y + f); PRINTF
}
Copy the code

16. Main function content

int main(a)
{
 DeawMap();
 code_y = rand() % 7 + 1;
 while (1)
 {
  Return = BlockRand(code_y);
  code_y = rand() % 7 + 1;
  Show(code_y);
  ShowBlock(&Return);
 }
 system("pause>nul");
 return 0;
}
Copy the code

The complete code is attached, or you can download it yourself

//vs2015 compiles and runs
#include<stdio.h>
#include<time.h>
#include<Windows.h>
#define HEIGHT  28  // Set the map height
#define WIDTH   20  // Set the map width
#define ZERO    1
#define HEIGHT_1 18
#define Loca_y    6
#define Loca_x    25
#define PRINTF  printf("■");
#define LINE    printf("\n");
#define EMPTY   printf("");
typedef struct Tetris
{
 int x_1, y_1;   // The primary x coordinate, the primary y coordinate, the following three are subordinate
 int x_2, y_2;
 int x_3, y_3;
 int x_4, y_4;
 int code;//7 block form codes
 Tetris * next;
}Tetris;
void DeawMap(a);                     	// Draw a map
Tetris * BlockRand(int code);    	 	// Random main block generation
void JudgeDirection(Tetris ** Block); // Key response
void Form(Tetris ** Block);      		// Box coordinates are all set
void ShowBlock(Tetris ** Block);    	// Display the complete block
int JudgeWall(Tetris ** Block);     	// Determine the left and right boundaries
void MoveCursor(int x, int y);      	// Moving the cursor does not flash because the entire map is not refreshed at a time, only a specific area is refreshed
void SetColour(int c);              	// Color Settings
int JudgeGroud(Tetris * Phead, Tetris ** Block);// Determine the landing
void JudgeEntire(Tetris * Head);    	// Check whether the entire row is full
void NewEntire(Tetris * head, int y);  // If the above function is true, if clear the line, and refresh the map
void Show(int n);        			// Displays information about the score of the next block. If you want to add some information, you can modify it in this function
void Location(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f);   // Update coordinate 1
void Location_y(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f); // Update coordinate 2
void Location_x(int x, int y, int a, int b, int c, int d, int e, int f);                  // Update information
Tetris *Phead = NULL;   // Link header pointer
Tetris *Pend = NULL;    // follow the pointer (tail interpolation required)
Tetris * Return = NULL; // Node address returns
int form = 0; // Determine the form
int UP = 0;   // Determine the speed of descent
int code_y = 0;// Random form
int fengs = 0; / / score

int main(a)
{
 DeawMap();
 code_y = rand() % 7 + 1;
 while (1)
 {
  Return = BlockRand(code_y);
  code_y = rand() % 7 + 1;
  Show(code_y);
  ShowBlock(&Return);
 }
 system("pause>nul");
 return 0;
}

void DeawMap(a)
{
 for (int i = 0; i < WIDTH; i++)PRINTF LINE  / / on the border
  for (int i = 1; i < HEIGHT - 1; i++)          // Prints the left and right borders
  {
   for (int j = 0; j < WIDTH; j++)
   {
    if (j == 0 || j == WIDTH - 1)
    {
     PRINTF
      if (j == WIDTH - 1)LINE
    }
    else EMPTY
   }
  }
 for (int i = 0; i < WIDTH; i++)PRINTF LINE  / / bottom border
 system("color 03");
}

void Location(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f)
{
 (*Block)->x_1 = (*Block)->x_1 + x;
 (*Block)->y_1 = (*Block)->y_1 + y;
 (*Block)->x_2 = (*Block)->x_1 + a;
 (*Block)->y_2 = (*Block)->y_1 + b;
 (*Block)->x_3 = (*Block)->x_1 + c;
 (*Block)->y_3 = (*Block)->y_1 + d;
 (*Block)->x_4 = (*Block)->x_1 + e;
 (*Block)->y_4 = (*Block)->y_1 + f;
}

void Location_y(Tetris ** Block, int x, int y, int a, int b, int c, int d, int e, int f)
{
 (*Block)->x_1 = (*Block)->x_1 + x;
 (*Block)->y_1 = (*Block)->y_1 + y;
 (*Block)->x_2 = (*Block)->x_2 + a;
 (*Block)->y_2 = (*Block)->y_2 + b;
 (*Block)->x_3 = (*Block)->x_3 + c;
 (*Block)->y_3 = (*Block)->y_3 + d;
 (*Block)->x_4 = (*Block)->x_4 + e;
 (*Block)->y_4 = (*Block)->y_4 + f;
}

Tetris * BlockRand(int code_y)
{
 srand((int)time(0));
 Tetris * Block = (Tetris*)malloc(sizeof(Tetris));
 Block->x_1 = 8;
 Block->y_1 = 4;// set the coordinates of the initial center block to (8,4).
 Block->code = code_y;
 if (Phead == NULL)Phead = Block;
 else Pend->next = Block;
 Block->next = NULL;
 Pend = Block;
 return Block;
}

void ShowBlock(Tetris ** Block)
{
 while (1)
 {

  Form(&Return); 
  if ((*Block)->code == 1)SetColour(13);
  if ((*Block)->code == 2)SetColour(15);
  if ((*Block)->code == 3)SetColour(12);
  if ((*Block)->code == 4)SetColour(10);
  if ((*Block)->code == 5)SetColour(6);
  if ((*Block)->code == 6)SetColour(4);
  if ((*Block)->code == 7)SetColour(8);
  MoveCursor((*Block)->x_1, (*Block)->y_1); PRINTF
  MoveCursor((*Block)->x_2, (*Block)->y_2); PRINTF
  MoveCursor((*Block)->x_3, (*Block)->y_3); PRINTF
  MoveCursor((*Block)->x_4, (*Block)->y_4); PRINTF
  if (JudgeGroud(Phead, &Return) == 0)
  {
   system("color 03");
   break;
  }
  if (UP == 0)
  {
   for (int i = 0; i <= 400000000; i++) {}
  }
  if (UP == 1)
  {
   for (int i = 0; i <= 40000000; i++) {}
   UP = 0;
  }
  MoveCursor((*Block)->x_1, (*Block)->y_1); EMPTY
  MoveCursor((*Block)->x_2, (*Block)->y_2); EMPTY
  MoveCursor((*Block)->x_3, (*Block)->y_3); EMPTY
  MoveCursor((*Block)->x_4, (*Block)->y_4); EMPTY
  Location_y(&Return, 0.1.0.1.0.1.0.1); JudgeDirection(&Return); JudgeEntire(Phead); }}void JudgeDirection(Tetris ** Block)
{
 if (GetAsyncKeyState(VK_UP) && 0x8000)
 {
  form += 1;
  if (form == 4)
  {
   form = 0;
  }
  Form(&Return);
 }
 if (GetAsyncKeyState(VK_DOWN) && 0x8000)
 {
  // Accelerate down time
  UP = 1;
 }
 if (GetAsyncKeyState(VK_LEFT) && 0x8000)
 {
  // Move left
  if(JudgeWall(&Return) ! =- 1) Location_y(&Return, - 1.0.- 1.0.- 1.0.- 1.0);
 }
 if (GetAsyncKeyState(VK_RIGHT) && 0x8000)
 {
  // Move to the right
  if(JudgeWall(&Return) ! =2 -) Location_y(&Return, 1.0.1.0.1.0.1.0);
 }
 if (GetAsyncKeyState(VK_ESCAPE) && 0x0D)
 {
  MoveCursor(27.15);
  printf("Game pause");
  //判断Esc
  while (1)
  {
   if (GetAsyncKeyState(VK_ESCAPE) && 0x0D)
   {
    MoveCursor(27.15);
    printf("");
    break; }}}}void Form(Tetris ** Block)
{
 // Determine which category first, then subdivide
 switch ((*Block)->code)
 {
 case 1:
  if (form == 0)Location(&Return, 0.0.- 1.0.0.- 1.1.0);
  if (form == 1)Location(&Return, 0.0.0.1.0.- 1.1.0);
  if (form == 2)Location(&Return, 0.0.0.1.- 1.0.1.0);
  if (form == 3)Location(&Return, 0.0.0.1.- 1.0.0.- 1);
  break;
 case 2:
  Location(&Return, 0.0.1.0.0.1.1.1);
  break;
 case 3:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.- 1.0.1.0.2);
  if (form == 1 || form == 3)Location(&Return, 0.0.- 1.0.1.0.2.0);
  break;
 case 4:
  if (form == 0)Location(&Return, 0.0.- 1.0.1.0.1.- 1);
  if (form == 1)Location(&Return, 0.0.0.- 1.1.0.0.2 -);
  if (form == 2)Location(&Return, 0.0.0.- 1.1.- 1.2.- 1);
  if (form == 3)Location(&Return, 0.0.0.- 1.0.2 -.- 1.2 -);
  break;
 case 5:
  if (form == 0)Location(&Return, 0.0.1.0.2.0.0.- 1);
  if (form == 1)Location(&Return, 0.0.1.0.1.- 1.1.2 -);
  if (form == 2)Location(&Return, 0.0.1.0.2.0.2.1);
  if (form == 3)Location(&Return, 0.0.1.0.0.1.0.2);
  break;
 case 6:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.- 1.1.0.1.1);
  if (form == 1 || form == 3)Location(&Return, 0.0.0.- 1.1.- 1.- 1.0);
  break;
 case 7:
  if (form == 0 || form == 2)Location(&Return, 0.0.0.1.1.0.1.- 1);
  if (form == 1 || form == 3)Location(&Return, 0.0.0.1.- 1.0.1.1); }}void MoveCursor(int x, int y)// Set the cursor position (that is, the start of the output display)
{
 COORD pos = { x * 2,y };
 HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);// Get a handle to the standard output
 SetConsoleCursorPosition(output, pos); // Set the console cursor position
}

void SetColour(int c)
{
 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);// The API function can change the console color
}
int JudgeWall(Tetris ** Block)
{
 if ((*Block)->x_1 == ZERO || (*Block)->x_2 == ZERO || (*Block)->x_3 == ZERO || (*Block)->x_4 == ZERO)return - 1;
 if ((*Block)->x_1 == HEIGHT_1 || (*Block)->x_2 == HEIGHT_1 || (*Block)->x_3 == HEIGHT_1 || (*Block)->x_4 == HEIGHT_1)return 2 -;
 return 0;
}

int JudgeGroud(Tetris * Phead, Tetris ** Block)
{
 
 Tetris * P = Phead;
 // If you reach the lowest level. Go straight through the next loop
 if ((*Block)->y_1 == 26 || (*Block)->y_2 == 26 || (*Block)->y_3 == 26 || (*Block)->y_4 == 26)return 0;
 while(P->next ! =NULL)
 {
  if (P->y_1 == (*Block)->y_1 + 1)
  {
   if (P->x_1 == (*Block)->x_1)return 0;
  }
  if (P->y_2 == (*Block)->y_1 + 1)
  {
   if (P->x_2 == (*Block)->x_1)return 0;
  }
  if (P->y_3 == (*Block)->y_1 + 1)
  {
   if (P->x_3 == (*Block)->x_1)return 0;
  }
  if (P->y_4 == (*Block)->y_1 + 1)
  {
   if (P->x_4 == (*Block)->x_1)return 0;
  }
  if (P->y_1 == (*Block)->y_2 + 1)
  {
   if (P->x_1 == (*Block)->x_2)return 0;
  }
  if (P->y_2 == (*Block)->y_2 + 1)
  {
   if (P->x_2 == (*Block)->x_2)return 0;
  }
  if (P->y_3 == (*Block)->y_2 + 1)
  {
   if (P->x_3 == (*Block)->x_2)return 0;
  }
  if (P->y_4 == (*Block)->y_2 + 1)
  {
   if (P->x_4 == (*Block)->x_2)return 0;
  }
  if (P->y_1 == (*Block)->y_3 + 1)
  {
   if (P->x_1 == (*Block)->x_3)return 0;
  }
  if (P->y_2 == (*Block)->y_3 + 1)
  {
   if (P->x_2 == (*Block)->x_3)return 0;
  }
  if (P->y_3 == (*Block)->y_3 + 1)
  {
   if (P->x_3 == (*Block)->x_3)return 0;
  }
  if (P->y_4 == (*Block)->y_3 + 1)
  {
   if (P->x_4 == (*Block)->x_3)return 0;
  }
  if (P->y_1 == (*Block)->y_4 + 1)
  {
   if (P->x_1 == (*Block)->x_4)return 0;
  }
  if (P->y_2 == (*Block)->y_4 + 1)
  {
   if (P->x_2 == (*Block)->x_4)return 0;
  }
  if (P->y_3 == (*Block)->y_4 + 1)
  {
   if (P->x_3 == (*Block)->x_4)return 0;
  }
  if (P->y_4 == (*Block)->y_4 + 1)
  {
   if (P->x_4 == (*Block)->x_4)return 0;
  }
  P = P->next;
 }
 return 1;
}

void JudgeEntire(Tetris * Head)
{
 Tetris * PHead = Head;
 // From 1 to 26
 for (int y = 26; y >= 1; y--)
 {
  int sum = 0;
  while(PHead->next ! =NULL)
  {
   if (PHead->y_1 == y)sum++;
   if (PHead->y_2 == y)sum++;
   if (PHead->y_3 == y)sum++;
   if (PHead->y_4 == y)sum++;
   MoveCursor(20.28);
   PHead = PHead->next;
  }
  PHead = Head;
  if (sum == 18)
  {
  // If there is a line, execute NewEntire() to empty the line and drop all y by one unit.
   NewEntire(Phead, y);
   fengs += 10;
   Show(code_y);
  }
  sum = 0; }}void NewEntire(Tetris * head,int y)
{
 Tetris * PHead = head;
 while(PHead->next ! =NULL)
 {
  if (PHead->y_1 == y)
  {
   MoveCursor(PHead->x_1, PHead->y_1); EMPTY
   PHead->x_1 = 99;
   PHead->y_1 = 99;
  }
  if (PHead->y_2 == y)
  {
   MoveCursor(PHead->x_2, PHead->y_2); EMPTY
   PHead->x_2 = 99;
   PHead->y_2 = 99;
  }
  if (PHead->y_3 == y)
  {
   MoveCursor(PHead->x_3, PHead->y_3); EMPTY
   PHead->x_3 = 99;
   PHead->y_3 = 99;
  }
  if (PHead->y_4 == y)
  {
   MoveCursor(PHead->x_4, PHead->y_4); EMPTY
   PHead->x_4 = 99;
   PHead->y_4 = 99;
  }
  PHead = PHead->next;
 }
 PHead = head;
 while(PHead->next ! =NULL)
 {
  if (PHead->y_1 < y)
  {
   MoveCursor(PHead->x_1, PHead->y_1); EMPTY
   PHead->y_1 += 1;
   MoveCursor(PHead->x_1, PHead->y_1); PRINTF
  }
  if (PHead->y_2 < y)
  {
   MoveCursor(PHead->x_2, PHead->y_2); EMPTY
   PHead->y_2 += 1;
   MoveCursor(PHead->x_2, PHead->y_2); PRINTF
  }
  if (PHead->y_3 < y)
  {
   MoveCursor(PHead->x_3, PHead->y_3); EMPTY
   PHead->y_3 += 1;
   MoveCursor(PHead->x_3, PHead->y_3); PRINTF
  }
  if (PHead->y_4 < y)
  {
   MoveCursor(PHead->x_4, PHead->y_4); EMPTY
   PHead->y_4 += 1; MoveCursor(PHead->x_4, PHead->y_4); PRINTF } PHead = PHead->next; }}void Show(int n)
{
 // Display the next square
 // Clear the area first
 for (int j = 4; j <= 8; j++)
 {
  for (int i = 23; i <= 28; i++)
  {
   MoveCursor(i, j);  EMPTY
  }
 }
 MoveCursor(24.3); 
 printf("Next block type:");
 MoveCursor(24.10);
 printf("Game score: % D", fengs);
 MoveCursor(24.12);
 printf("Made by Fdog, it's a must.");
 if (n == 1)
 {
  SetColour(13);
  Location_x(- 1.0.0.0.1.0.- 1.- 1);
 }
 if (n == 2)
 {
  SetColour(15);
  Location_x(0.0.1.0.- 1.1.1.1);
 }
 if (n == 3)
 {
  SetColour(12);
  Location_x(0.0.1.0.2.0.3.0);
 }
 if (n == 4)
 {
  SetColour(10);
  Location_x(0.0.1.0.2.0.2.- 1);
 }
 if (n == 5)
 {
  SetColour(6);
  Location_x(0.- 1.0.0.1.0.2.0);
 }
 if (n == 6)
 {
  SetColour(4);
  Location_x(- 1.- 1.- 1.0.0.0.0.1);
 }
 if (n == 7)
 {
  SetColour(8);
  Location_x(0.- 1.0.0.- 1.0.- 1.1); }}void Location_x(int x, int y, int a, int b, int c, int d, int e, int f)
{
     MoveCursor(Loca_x+x, Loca_y+y); PRINTF
  MoveCursor(Loca_x+a, Loca_y+b); PRINTF
  MoveCursor(Loca_x+c, Loca_y+d); PRINTF
  MoveCursor(Loca_x+e, Loca_y+f); PRINTF
}
Copy the code

If there are mistakes, welcome to criticize, welcome to discuss.

== every article sentence: life, is to face reality smile, is to look at the future over obstacles; Life, is to use the scissors of the heart, in the road of life cut leaves green branches; Life is a big, bright and smiling light lit in the depths of the soul in the face of confusion or darkness. = =