当前位置:网站首页>C actual combat - high configuration version of Snake game design
C actual combat - high configuration version of Snake game design
2022-06-29 07:48:00 【Mertrix_ ITCH】
Don't talk much , First, the picture above is for respect (●´∀`●)ノ


With you の Mian : snake Demo As a C The classic development project of language , More suitable for beginners to practice . See the essence through the procedure , There are many ways for us to learn from this project 、 Improve the knowledge point : Array 、 The pointer 、 Circular linked list 、 Multi file operation 、 Three major structural applications …… wait .“ theory + practice ”, I believe that you can get started by Demo Would be right C Have a better understanding .
Due to other recent delays , The complete design process notes have not been completed yet , But I will make it up as soon as possible , Let's share the source code first , Looking forward to learning and communicating together .
Put forward some interesting and referential parts separately , See the attachment for the complete source code .
1. Draw characters draw – The snake
// Draw characters draw -- The snake
int printSnake(void){
// Clear the screen
system("cls");
gotoXY(35, 1);
setColor(6);
printf("/^\\/^\\"); // Snake eye
gotoXY(34, 2);
printf("|__| 0"); // Snake eye
gotoXY(33, 2);
setColor(2);
printf("_");
gotoXY(25, 3);
setColor(12);
printf("\\/"); // Snake letter
gotoXY(31, 3);
setColor(2);
printf("/");
gotoXY(37, 3);
setColor(6);
printf("\\_/"); // Snake eye
gotoXY(41, 3);
setColor(10);
printf("\\");
gotoXY(26, 4);
setColor(12);
printf("\\____"); // The tongue
gotoXY(32, 4);
printf("_________/");
gotoXY(31, 4);
setColor(2);
printf("|");
gotoXY(42, 4);
setColor(10);
printf("\\");
gotoXY(31, 5);
setColor(2);
printf("\\_______"); // Snake mouth
gotoXY(43, 5);
setColor(10);
printf("\\");
gotoXY(38, 6);
printf(" | | \\");
// The following are all snake body paintings
gotoXY(38, 7);
printf(" / / \\ \\");
gotoXY(37, 8);
printf(" / / \\ \\");
gotoXY(36, 9);
printf(" / / \\ \\");
gotoXY(35, 10);
printf(" / / \\ \\");
gotoXY(34, 11);
printf(" / / _----_ \\ \\");
gotoXY(33, 12);
printf(" / / _--~ --_ | |");
gotoXY(33, 13);
printf("( ( _----~ _--_ --_ _/ |");
gotoXY(34, 14);
printf("\\ ~-——-~ --~--- ~-- ~-_-~ /");
gotoXY(35, 15);
printf("\\ -—~ ~—- -—~");
gotoXY(36, 16);
printf("~—-----—~ ~—---—~ ");
return 0;
}
2. The welcome screen
int i, j;
int n;
// Display character picture
printSnake();
// Output title
setColor(11);
// Move the cursor
gotoXY(49, 18);
printf(" Snake game \n");
// Set text color
setColor(14);
// Print game borders
for (i = 20; i <= 26; i++){
// The control line
for (j = 27; j <= 74; j++) // Control the column
{
// Positioning cursor
gotoXY(j, i);
if (i == 20 || i == 26){
printf("-");
}
else if (j == 27 || j == 74){
printf("|");
}
else{
printf(" ");
}
}
}
// Output menu
// Set text color
setColor(12);
gotoXY(35, 22);
printf("1. Start the game ");
gotoXY(55, 22);
printf("2. Game Description ");
gotoXY(35, 24);
printf("3. Quit the game ");
gotoXY(35, 24);
printf("3. Quit the game ");
// Output user selection prompt
gotoXY(27, 27);
printf(" Please select [1 2 3]:");
// Wait for the user to enter a number
scanf("%d", &n);
// Read carriage return characters
getchar();
return n;
}
3. Initialize snake
// Initialize snake
int initSnake(void)
{
int i = 0;
snake_t *new = NULL;
snake_t *tmp = NULL;
// Loop creation 4 Each node
for (i = 0; i < 4; i++){
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
break;
}
memset(new, 0, sizeof(snake_t));
// Initialize Columns It's an even number
new->x = 24 + i * 2;
// Initialization line
new->y = 5;
// The first interpolation
new->next = head;
head = new;
}
// Draw a snake
tmp = head;
while (NULL != tmp)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// Point to next node
tmp = tmp->next;
}
return 0;
}
4. Random food
// Random food
// Random food
int randFood(void)
{
snake_t *new = NULL;
snake_t *tmp = NULL;
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
return -1;
}
// Cycle random food Make sure the food is not in the snake
while (1)
{
// Zero clearing
memset(new, 0, sizeof(snake_t));
// Random x value
while (1)
{
// Random x value It's an even number (2,54)
//rand() %53 -->(0, 52) -->+2 -->(2,54)
new->x = rand() % 53 + 2;
if (new->x % 2 == 0)
{
break;
}
}
//rand() To produce a random number
//(1,25)
//rand( ) % 25 --> (0,24) -->+1 -->(1,25)
new->y = rand() % 25 + 1;
// Judge that the food cannot be on the snake
tmp = head;
while (NULL != tmp)
{
if ((tmp->x == new->x) && (tmp->y == new->y))
{
break;
}
tmp = tmp->next;
}
// The food is not on the snake
if (NULL == tmp)
{
gotoXY(new->x, new->y);
setColor(12);
printf("●");
// Food pointer
food = new;
break;
}
else
{
continue;
}
}
return 0;
}
5. The movement of the snake
int moveSnake(void)
{
snake_t *new = NULL;
snake_t *tmp = NULL;
snake_t *save = NULL;
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
return -1;
}
memset(new, 0, sizeof(snake_t));
// Up
if (direction == UP)
{
new->x = head->x;
new->y = head->y - 1;
}
// Down
if (direction == DOWN)
{
new->x = head->x;
new->y = head->y + 1;
}
// towards the left
if (direction == LEFT)
{
new->x = head->x - 2;
new->y = head->y;
}
// towards the right
if (direction == RIGHT)
{
new->x = head->x + 2;
new->y = head->y;
}
// The first interpolation
new->next = head;
head = new;
// Use the temporary node to point to the first node in the linked list
tmp = head;
// Whether the front is food
if ((head->x == food->x) && (head->y == food->y))
{
while (NULL != tmp)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// Point to next node
tmp = tmp->next;
}
// The score increases after eating food
score = score + add;
// Random food
randFood();
}
else
{
// Delete last node
while (NULL != tmp->next)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// preservation tmp node
save = tmp;
// Point to next node
tmp = tmp->next;
}
gotoXY(tmp->x, tmp->y);
setColor(3);
printf("■");
save->next = NULL;
free(tmp);
tmp = NULL;
}
return 0;
}
6. Writing documents
// Writing documents
int writeFile(void)
{
FILE *fp = NULL;
// Open file
fp = fopen("data.txt", "w");
if (NULL == fp)
{
printf(" fail to open file ..\n");
return -1;
}
// Writing documents
fprintf(fp, "%d", score);
// Close file
fclose(fp);
return 0;
}
— Source code :------------------------------------------------------------------------------------------------------------------------
1.snake.c
#define _CRT_SECURE_NO_WARNINGS
#include"snake.h"
// score
int score = 0;
// Increase score each time
int add = 1;
// The moving direction of the snake
int direction = RIGHT;
// Game exit status
int endStatus = 0;
// Sleep time
int sleepTime = 250;
// Snakehead node pointer Always point to the snake head
snake_t *head = NULL;
// Food node pointer
snake_t *food = NULL;
// Set the terminal font color
int setColor(int c){
// Set text color
// The first parameter : Standard output handle
// The second parameter : The value of color
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
return 0;
}
// Set cursor position
int gotoXY(int x, int y){
COORD c;
// Abscissa
c.X = x;
// Ordinate
c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
return 0;
}
// Draw characters draw -- The snake
int printSnake(void){
// Clear the screen
system("cls");
gotoXY(35, 1);
setColor(6);
printf("/^\\/^\\"); // Snake eye
gotoXY(34, 2);
printf("|__| 0"); // Snake eye
gotoXY(33, 2);
setColor(2);
printf("_");
gotoXY(25, 3);
setColor(12);
printf("\\/"); // Snake letter
gotoXY(31, 3);
setColor(2);
printf("/");
gotoXY(37, 3);
setColor(6);
printf("\\_/"); // Snake eye
gotoXY(41, 3);
setColor(10);
printf("\\");
gotoXY(26, 4);
setColor(12);
printf("\\____"); // The tongue
gotoXY(32, 4);
printf("_________/");
gotoXY(31, 4);
setColor(2);
printf("|");
gotoXY(42, 4);
setColor(10);
printf("\\");
gotoXY(31, 5);
setColor(2);
printf("\\_______"); // Snake mouth
gotoXY(43, 5);
setColor(10);
printf("\\");
gotoXY(38, 6);
printf(" | | \\");
// The following are all snake body paintings
gotoXY(38, 7);
printf(" / / \\ \\");
gotoXY(37, 8);
printf(" / / \\ \\");
gotoXY(36, 9);
printf(" / / \\ \\");
gotoXY(35, 10);
printf(" / / \\ \\");
gotoXY(34, 11);
printf(" / / _----_ \\ \\");
gotoXY(33, 12);
printf(" / / _--~ --_ | |");
gotoXY(33, 13);
printf("( ( _----~ _--_ --_ _/ |");
gotoXY(34, 14);
printf("\\ ~-——-~ --~--- ~-- ~-_-~ /");
gotoXY(35, 15);
printf("\\ -—~ ~—- -—~");
gotoXY(36, 16);
printf("~—-----—~ ~—---—~ ");
return 0;
}
// The welcome screen
int welcomeGame(void){
int i, j;
int n;
// Display character picture
printSnake();
// Output title
setColor(11);
// Move the cursor
gotoXY(49, 18);
printf(" Snake game \n");
// Set text color
setColor(14);
// Print game borders
for (i = 20; i <= 26; i++){
// The control line
for (j = 27; j <= 74; j++) // Control the column
{
// Positioning cursor
gotoXY(j, i);
if (i == 20 || i == 26){
printf("-");
}
else if (j == 27 || j == 74){
printf("|");
}
else{
printf(" ");
}
}
}
// Output menu
// Set text color
setColor(12);
gotoXY(35, 22);
printf("1. Start the game ");
gotoXY(55, 22);
printf("2. Game Description ");
gotoXY(35, 24);
printf("3. Quit the game ");
gotoXY(35, 24);
printf("3. Quit the game ");
// Output user selection prompt
gotoXY(27, 27);
printf(" Please select [1 2 3]:");
// Wait for the user to enter a number
scanf("%d", &n);
// Read carriage return characters
getchar();
return n;
}
// Show game description
int aboutGame(void)
{
int i, j;
// Clear the screen
system("cls");
// Show title
setColor(13);
gotoXY(44, 3);
printf(" Game Description ");
for (i = 6; i <= 22; i++){
// That's ok
for (j = 20; j <= 75; j++){
// Column
// Set the cursor
gotoXY(j, i);
if (i == 6 || i == 22)
{
printf("=");
}
else if (j == 20 || j == 75)
{
printf("|");
}
else
{
printf(" ");
}
}
}
// Output game description list
gotoXY(30, 8);
setColor(3);
printf("* 1. Don't hit the wall , You can't bite yourself ");
gotoXY(30, 11);
setColor(5);
printf("* 2.F1 Speed up , F2 Slow down and move forward ");
gotoXY(30, 14);
setColor(11);
printf("* 3. Use spaces to pause or resume the game ");
gotoXY(30, 17);
setColor(13);
printf("* 4. Use ↑↓→← Control the forward direction ");
gotoXY(30, 20);
setColor(14);
printf("* 5. Press down Esc Keyboard exit game ");
gotoXY(20, 24);
setColor(12);
printf(" Please press enter to return to the main interface ");
return 0;
}
// Output game map
int printMap(void)
{
int i, j;
// Clear the screen
system("cls");
// That's ok 27 That's ok
for (i = 0; i < 27; i++){
// A square occupies 2 Column
for (j = 0; j < 57; j = j + 2){
gotoXY(j, i);
// Frame
if (i == 0 || i == 26 || j == 0 || j == 56)
{
setColor(5);
printf("□");
}
else
{
setColor(3);
printf("■");
}
}
}
return 0;
}
// Show tips and scores
int showScoreTips(void)
{
int highScore = 0;
// Show the highest score File read
gotoXY(64, 4);
setColor(3);
highScore = readFile();
printf("** Record the highest score **:%d ", highScore);
// Show the score
gotoXY(64, 8);
setColor(14);
printf(" score :%d", score);
// Show warm tips
gotoXY(72, 11);
setColor(12);
printf(" temperature Xin carry in ");
// Output top and bottom borders
setColor(10);
gotoXY(60, 13);
printf("========================================");
gotoXY(60, 25);
printf("========================================");
setColor(13);
gotoXY(64, 14);
printf("※ Eat each food and score :%d branch ", add);
gotoXY(64, 16);
printf("※ Don't hit the wall , Don't bump into yourself ");
gotoXY(64, 18);
printf("※ F1 Speed up ,F2 Slow down and move forward ");
gotoXY(64, 20);
printf("※ Use the space bar to pause or resume the game ");
gotoXY(64, 22);
printf("※ Use ↑↓→← Control the forward direction ");
gotoXY(64, 24);
printf("※ Press down Esc Keyboard exit game ");
return 0;
}
// Read the highest score record from the file
int readFile(void)
{
int n = 0;
FILE *fp = NULL;
// Open file r-- Reading mode
fp = fopen("data.txt", "r");
if (NULL == fp)
{
printf(" fail to open file …\n");
return 1;
}
// Reading documents fread fscanf
// Read a... From a file int type Save to n variable
fscanf(fp, "%d", &n);
// Close file
fclose(fp);
return n;
}
// Initialize snake
int initSnake(void)
{
int i = 0;
snake_t *new = NULL;
snake_t *tmp = NULL;
// Loop creation 4 Each node
for (i = 0; i < 4; i++){
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
break;
}
memset(new, 0, sizeof(snake_t));
// Initialize Columns It's an even number
new->x = 24 + i * 2;
// Initialization line
new->y = 5;
// The first interpolation
new->next = head;
head = new;
}
// Draw a snake
tmp = head;
while (NULL != tmp)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// Point to next node
tmp = tmp->next;
}
return 0;
}
// Random food
int randFood(void)
{
snake_t *new = NULL;
snake_t *tmp = NULL;
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
return -1;
}
// Cycle random food Make sure the food is not in the snake
while (1)
{
// Zero clearing
memset(new, 0, sizeof(snake_t));
// Random x value
while (1)
{
// Random x value It's an even number (2,54)
//rand() %53 -->(0, 52) -->+2 -->(2,54)
new->x = rand() % 53 + 2;
if (new->x % 2 == 0)
{
break;
}
}
//rand() To produce a random number
//(1,25)
//rand( ) % 25 --> (0,24) -->+1 -->(1,25)
new->y = rand() % 25 + 1;
// Judge that the food cannot be on the snake
tmp = head;
while (NULL != tmp)
{
if ((tmp->x == new->x) && (tmp->y == new->y))
{
break;
}
tmp = tmp->next;
}
// The food is not on the snake
if (NULL == tmp)
{
gotoXY(new->x, new->y);
setColor(12);
printf("●");
// Food pointer
food = new;
break;
}
else
{
continue;
}
}
return 0;
}
// The movement of the snake
int moveSnake(void)
{
snake_t *new = NULL;
snake_t *tmp = NULL;
snake_t *save = NULL;
// Allocate space
new = malloc(sizeof(snake_t));
if (NULL == new)
{
printf("malloc failed…\n");
return -1;
}
memset(new, 0, sizeof(snake_t));
// Up
if (direction == UP)
{
new->x = head->x;
new->y = head->y - 1;
}
// Down
if (direction == DOWN)
{
new->x = head->x;
new->y = head->y + 1;
}
// towards the left
if (direction == LEFT)
{
new->x = head->x - 2;
new->y = head->y;
}
// towards the right
if (direction == RIGHT)
{
new->x = head->x + 2;
new->y = head->y;
}
// The first interpolation
new->next = head;
head = new;
// Use the temporary node to point to the first node in the linked list
tmp = head;
// Whether the front is food
if ((head->x == food->x) && (head->y == food->y))
{
while (NULL != tmp)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// Point to next node
tmp = tmp->next;
}
// The score increases after eating food
score = score + add;
// Random food
randFood();
}
else
{
// Delete last node
while (NULL != tmp->next)
{
// Set the color of the snake to yellow
setColor(14);
gotoXY(tmp->x, tmp->y);
// If it's the first node Output circular symbol
if (head == tmp)
{
printf("●");
}
else
{
printf("*");
}
// preservation tmp node
save = tmp;
// Point to next node
tmp = tmp->next;
}
gotoXY(tmp->x, tmp->y);
setColor(3);
printf("■");
save->next = NULL;
free(tmp);
tmp = NULL;
}
return 0;
}
// Press the key to control the movement of the snake
int moveKeyControl(void)
{
// Default right
direction = RIGHT;
while (1)
{
// Update display scores and tips
showScoreTips();
// Up
if (GetAsyncKeyState(VK_UP) && direction != DOWN)
{
direction = UP;
}
// Down
if (GetAsyncKeyState(VK_DOWN) && direction != UP)
{
direction = DOWN;
}
// towards the left
if (GetAsyncKeyState(VK_LEFT) && direction != RIGHT)
{
direction = LEFT;
}
// towards the right
if (GetAsyncKeyState(VK_RIGHT) && direction != LEFT)
{
direction = RIGHT;
}
// Press the space bar Pause or resume
if (GetAsyncKeyState(VK_SPACE))
{
while (1)
{
if (GetAsyncKeyState(VK_SPACE))
{
break;
}
// sleep 200ms
Sleep(200);
}
}
// Press down F5 Speed up
if (GetAsyncKeyState(VK_F2))
{
speedUp();
}
// Press down F6 Slow down
if (GetAsyncKeyState(VK_F2))
{
speedDown();
}
// Press down Esc End the game
if (GetAsyncKeyState(VK_ESCAPE))
{
endStatus = 3;
endGame();
break;
}
moveSnake();
// Judge if the snake hit the wall
if (isHitWall())
{
endStatus = 1;
endGame();
break;
}
// Judge whether the snake bit itself
if (isBitSelf())
{
endStatus = 2;
endGame();
break;
}
Sleep(sleepTime);
}
return 0;
}
// Move faster
int speedUp(void)
{
if (sleepTime > 50)
{
sleepTime = sleepTime - 10;
// Increased scores
add = add + 2;
}
return 0;
}
// Slow down and move
int speedDown(void)
{
if (sleepTime<300)
{
sleepTime = sleepTime + 10;
// Increased scores
add = add - 2;
}
if (sleepTime > 250)
{
add = 1;
}
return 0;
}
// Judge if you hit the wall If you hit the wall and return 1 Otherwise return to 0
int isHitWall(void)
{
if (head->x == 0 || head->x == 56 || head->y == 0 || head->y == 26)
{
return 1;
}
return 0;
}
// Judge whether the snake bit itself If you bite yourself back 1 Otherwise return to 0
int isBitSelf(void)
{
snake_t *tmp = NULL;
tmp = head->next;
while (NULL != tmp)
{
if ((head->x == tmp->x) && (head->y == tmp->y))
{
return 1;
}
tmp = tmp->next;
}
return 0;
}
// Game failed borders
int failGameUi(void)
{
int i;
// Clear the screen
system("cls");
// Show title
gotoXY(44, 3);
setColor(12);
printf(" swim Play loss Defeat !!!");
// Output top and bottom borders
gotoXY(17, 5);
setColor(3);
printf("+----------------------------------------------------------------+");
gotoXY(17, 20);
printf("+----------------------------------------------------------------+");
for (i = 6; i < 20; i++)
{
gotoXY(17, i);
printf("|");
gotoXY(82, i);
printf("|");
}
return 0;
}
// Game failure prompt
int endGame(void)
{
int n;
int highScore = 0;
while (1)
{
// Display the failed interface border
failGameUi();
//1. Hit the wall
//2. Bite yourself
//3. Press down Esc key
gotoXY(38, 9);
setColor(12);
switch (endStatus)
{
//1. Hit the wall
case 1:
printf(" You hit the wall , Game over !!!");
break;
//2. Bite yourself
case 2:
printf(" You bit yourself , Game over !");
break;
//3. Press down Esc key
case 3:
printf(" You have ended the game , Game over ");
break;
default:
break;
}
// Show your score
gotoXY(43, 12);
setColor(13);
printf(" Your score :%d", score);
// Show the highest score
highScore = readFile();
// Display whether to brush records
gotoXY(38, 16);
setColor(10);
// No record
if (highScore > score)
{
printf(" Come on , It's still far from the highest score %d branch ", highScore - score);
}
else
{
printf(" congratulations , You have set a record !!!");
// Write the highest score into the file
writeFile(score);
}
// Show menu
gotoXY(25, 23);
setColor(12);
printf(" To play another game, please enter :1");
gotoXY(52, 23);
printf(" To exit directly, please enter :2");
gotoXY(46, 25);
setColor(11);
printf(" Please select :");
// Wait for the user to enter a number
scanf("%d", &n);
// Clear line breaks
getchar();
if (1 == n)
{
// Restore to original state
sleepTime = 250;
score = 0;
add = 1;
// Destroy the snake node
snakeDestroy();
// The initialization header pointer is null
head = NULL;
break;
}
else if (2 == n)
{
// End procedure
exit(0);
}
else
{
//
setColor(12);
gotoXY(30, 27);
printf(" Your input is wrong , Please re-enter , Press any key to continue ");
getchar();
continue;
}
}
return 0;
}
// Writing documents
int writeFile(void)
{
FILE *fp = NULL;
// Open file
fp = fopen("data.txt", "w");
if (NULL == fp)
{
printf(" fail to open file ..\n");
return -1;
}
// Writing documents
fprintf(fp, "%d", score);
// Close file
fclose(fp);
return 0;
}
// Destroy the snake node
int snakeDestroy(void)
{
snake_t *tmp = NULL;
snake_t *save = NULL;
// Point to the first node of the list
tmp = head;
while (NULL != tmp)
{
save = tmp->next;
free(tmp);
tmp = save;
}
head = NULL;
return 0;
}
- main.c file
#define _CRT_SECURE_NO_WARNINGS
#include"snake.h"
int main(){
int n;// Set the console width and height
system("mode con cols=100 lines=30");
// Set random seeds
srand((unsigned int)time(NULL));
while (1){
// Clear the screen
system("cls");
n = welcomeGame();
switch (n){
// Start the game
case 1:
//printf("Loading……\n");
printMap();
// Show warm tips
showScoreTips();
// Initialize snake
initSnake();
// Random food
randFood();
// Press the key to control the movement of the snake
moveKeyControl();
break;
// Game Description
case 2:
aboutGame();
//printf(" Game Description \n");
// Jump out of switch structure
break;
// Quit the game
case 3:
// End procedure
exit(0);
break;
default:
;
}
// Wait for the user to enter any character
getchar();
}
system("pause");
return 0;
}
3.*snake.h
#pragma once
// Standard inputs and outputs
#include<stdio.h>
// String processing related files
#include<string.h>
// General function related header file
#include<stdlib.h>
//WindowsAPI Related header file
#include<Windows.h>
// Time related header file
#include<time.h>
// Up
#define UP 1
// Down
#define DOWN 2
// towards the left
#define LEFT 3
// towards the right
#define RIGHT 4
// Declare the snake node structure type
typedef struct _snake_t{
// Express x Coordinate system
int x;
// Express y Coordinate value
int y;
// Point to the next node of the snake
struct _snake_t *next;
}snake_t;
// Set the terminal font color
int setColor(int c);
// Draw characters draw snakes
int printSnake(void);
// The welcome screen
int welcomeGame(void);
// Show game description
int aboutGame(void);
// Output game map
int printMap(void);
// Show tips and scores
int showScoreTips(void);
// Read the highest score record from the file
int readFile(void);
// Initialize snake
int initSnake(void);
// Random food
int randFood(void);
// Move the snake
int moveSnake(void);
// Press the key to control the movement of the snake
int moveKeyControl(void);
// Move faster
int speedUp(void);
// Slow down and move
int speedDown(void);
// Judge if you hit the wall
int isHitWall(void);
// Judge whether the snake bit itself
int isBitSelf(void);
// Game failed borders
int failGameUi(void);
// Game failure prompt
int endGame(void);
// Writing documents
int writeFile(int score);
// Destroy the snake node
int snakeDestroy(void);
边栏推荐
- Explain canfd message and format in AUTOSAR arxml in detail
- 指针引用数组元素
- From XX import* is equivalent to from XX import *, and no space is required
- 719. 找出第 K 小的数对距离(二分)
- ES中配置ext.dic文件不生效的原因
- 100 lectures on Excel advanced drawing skills (VI) - practical application cases of Gantt chart in project progress
- Vulnhub's dc9 target
- 从Nacos客户端谈Nacos配置中心
- [industrial control old horse] detailed explanation of design principle of pattern fountain based on PLC
- 小白大战指针 (上)
猜你喜欢

Appium自动化测试基础 — ADB常用命令(三)

Using cdockablepane to realize floating window in MFC

Reasons why the ext.dic file configured in ES does not take effect

Roblox sword nine sword two

Appium environment setup

matlab simulink 电网扫频仿真和分析

SQL injection bypass (6)
What tools do testers need to know

1032 Sharing

Prompt during packaging: property 'sqlsessionfactory' or 'sqlsessiontemplate'‘
随机推荐
游标长时间open导致表无法vacuum问题
719. 找出第 K 小的数对距离(二分)
ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
精选西门子PLC工程实例源码【共300套】
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
【工控老马】单片机与西门子S7-200通信原理详解
打包时提示: Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘
电检码配置
Blue Bridge Cup -- Analysis of the second batch of test questions of the 13th session
从Nacos客户端谈Nacos配置中心
Interviewer: why does database connection consume resources? Where are the resources consumed?
Schnuka: automatic tire grabbing installation, 3D visual positioning, automatic robot grabbing
施努卡:轮胎自动抓取安装,3D视觉定位,机器人自动抓取
Swin Transformer理论讲解
【量化投资系统】问题记录及解决方法
Cv:: mat and Base64 conversion (including picture compression and decompression)
tf. compat. v1.global_ variables
Compiling principle: the king's way
Problem solving -- > online OJ (13)
呕心沥血总结出来的MySQL常见错误以及解决方法(二)