Visual Studio C++/C game development — Two people implementation method + code explanation + algorithm optimization + successful demonstration + summary

Visual Studio cannot open source file “stdio.h” “time.h” (fixed)

See the end of the source

 

 

I. Problem description

The basic knowledge points in the data structure, such as stack, queue, linear table, graph, tree and so on, are applied to the actual problems, presented by small games or small tools and other procedures, requiring understanding of the basic structure and can be expanded, and finally achieve the purpose of application.

Second, preparation

Use Audacity to process the required audio and import it into the target folder

Use Photoshop to edit and convert the required image materials

Use the C++ program development features of the 2019 Visual Studio Community integrated environment for game design

Convert background, texture, head, body and food photos to BMP format in advance and transfer the pixels to the target folder

 

Iii. Analysis and implementation of some codes (see attachment for detailed codes)

Background wall color changes

Extension: The background wall is redesigned into a festive style with Chinese red elements, permeated with the festive color of the Spring Festival.

Implementation method:

Analysis: The purpose of this design is to create the background of the New Year square lion dance feeling, I think the Chinese red elements are also red elements, festive color makes the whole game national culture atmosphere more rich.

Map reference and text generation

Expand parts: players a snake as orange dragon scales, the head portrait of lion dance, on behalf of the lion dance, the player two snakes as blue dragon scales, head for the nien beast portrait, on behalf of the nien beast, food pictures, use red lantern and named player of lion dance, secondly, nien, game for xia to dance, and put into the theme image, on the right show related information, introduces the operation mode and the body length.

Implementation method:

Analysis: This game lion dance and nian (background) on New Year’s square for the lanterns game design inspiration comes from the legend of lion dance and nian, add the theme image play against corresponding double snake dance “xia”, all of the Chinese wind festival elements join to foil the red New Year Spring Festival atmosphere of festival activity the lion dance, the right side of the prompt and convenient players understand the game and score statistics operation.

 

Realization of two – person versus operation

Expansion: The game is expanded to a two-player battle, both sides can devour food to grow. The main game is to protect their own head, swallow food and use the body length advantage of the other side to encircle, if one side’s head hits the other side’s body, the other side wins, otherwise, to.

Implementation method:

Analysis: on the basis of the original added another player’s body parameters record operation control, food swallowing, wall death judgment, the principle of the algorithm remains unchanged, in addition to this also added the two sides of the death judgment, if one side of the head against the other side of the body, then determine the former death, vice versa. Increased the game’s playability and operability, but also appeared a lot of new problems, for example, the body and background overlay printing will lead to rapid flicker, causing visual discomfort, which will be solved in the later expansion.

 

Random generation of multiple foods

Expansion: Randomly generate multiple foods for two players to devour

Implementation method:

Analysis: Double against a snake food will definitely affect the game experience, so that food can be set to adjustable multiple food, in the first game at the start of the run or to generate multiple new random food, when a player to eat a food will add a body length, will generate a new random food at the same time, but also a new problem, For example, the generation of multiple food will overlap, new food will be generated on the old food or on the snake, the cost of food generation should be considered when the food is generated multiple, and the cost of food swallowing should be determined, and the printing of food and background overlap will flash, these problems will be solved in the later optimization expansion.

 

Solve the flicker problem of overlapping printing of food and body + structure optimization

Expansion: Establish an array to determine the position and state of body food, solve the problem of flashing body food caused by overlapping printing, optimize the structure to reduce the cost of the program.

Implementation method:

Analysis: the game will run or start again for the first time the body to determine arrays and judge food initialized to zero, the generated more food for the first time the food to determine weights of all the food in the array position 1, in the game at the same time before each print the body position determine array initialized weights set to 0, and the physical location where the weights updated to 1; When food is swallowed, reset the weight of the food determination array at this position to 0, and generate new food; When new food is generated, use the do-while statement to create a random position and then determine whether there is food in this position or whether this position is the player’s body. If it does not meet the requirements, it will regenerate. If it meets the requirements, the weight of the food determination array in this position will be set to 1. Add the judgement of body and food at this position when printing the background plate each time. If the weight of food judgement array here is 1 or the weight of body judgement array here is 1, the background plate will not be printed. If the two judgement weights are 0, the background plate will be printed. The above operation effectively solves the problem of wrong position printing caused by multiple foods, and the flicker problem caused by overlapping printing on the body and food with the background plate.

 

Background music “Dance of the Golden Snake”

Expansion: At the beginning of the game, the background music of “Golden Snake Dance” will be played automatically.

Implementation method:

The BGM “Golden Snake Dance” edited by Audacity in advance echoes the theme of the Golden Snake Dance, works together, and jointly highlights the Chinese red New Year festival lion dance atmosphere, and the intense and festive music also adds several unique styles to the experience of the game.

 

Opening Theme Picture

Extension: the theme image is displayed in the center of the window when the game is opened for the first time, and disappears when the game starts

Implementation method:

Analysis: By setting the global variable KK, the game is controlled to enter the opening picture printing function start () at the first start. The picture echoes the theme and satisfies the players visually when opening the game for the first time, thus improving the overall viewing level of the game.

 

The game starts with a quick redo

Expansion: Space controls the first start and quick restart of the game

Implementation method:

Analysis: When entering the game for the first time, press the space, the theme picture disappears, when the game is going on, press the space, quickly start again, enrich the operation content and game experience of players.

 

Four, the game running display

 

Five, the summary

On the basis of the original game has been completely modified and added, the game alone snake game mode is changed to a two-person snake fighting mode, both sides can grow by eating food. The main game is to protect their own head, swallow food and use the body length advantage of the other side to encircle, if one side’s head hits the other side’s body, the other side wins, otherwise, to. A number of modifications have greatly increased the gameplay of the game, while many bugs and problems have been relatively perfect solutions

Reflections (for reference only) : The game design that I gain a lot from the first clue, do not know where do to get the code base, change is a lot of bugs, in order to later, on the basis of the original can be censored and flexible innovation, I not only mastered the ability to write the game, more master the optimized structure, the ability to create games, Also to a certain extent to enhance their own aesthetic design ability. At the beginning of my goal is just to make a double snake game, like last week’s fire a mobile game snake snake (combat), namely the snakes to pk, a head and the other side of the body is to die, to conversely, determine the operation of the snakes and death code implementation process is very smooth, in the process of the other troubles, Two snake for a food, for example, is turned into a double game, but a sharp fall in the playability of the game, after recognizing this problem, and began to try to generate more than food, and generate multiple food as early as the idea of simply generate multiple food, but also found that multiple food make overlapping print has resulted in fewer and fewer food would appear, Or a food growth length is not in the case of a food in each generation to solve this problem when add the principles for judging the for loop, is used to determine whether the position is the snake body or for food, but after running found using the multilayer circulation structure cost too high, the program runs in food for more than ten number set, the program will often hang up, Reference wei-bin Chen teacher algorithm after many instances of this course is about the end to set up the global body with food position determine arrays, this way to make food at each update just a do – while statement to complete the update, greatly reduce the computational complexity, on this basis, through the determination of the array to add conditions to set up in the print, Solved the background piece of food with repeated print to flicker problem, the operation of the above process to basic forming, make the whole game is next to beautify the link, but considering the elements into the five-star red flag too rigid, and even lead to have the opposite effect, it was near the New Year, so thinking decided to red element under the category of expanding into the Chinese red, red, A began to think of himself with two snakes very close to the New Year festival music dance “xia”, but snakes set is too thin for food, then turn to the related information, game environment is defined as the square of the New Year, lion dance, the background color to choose Chinese red and golden, moral thriving, jixiangruyi, players head to the lion’s head portrait, Body choose orange dragon scales, the lion is a fierce, the symbol of auspicious, his dancing corresponds to the “lion dance”, the Chinese nation traditional culture and the food instead of lantern style means the New Year new atmosphere, for the lantern is representing the people a vision of a New Year, the second player selects the nien beast head portrait as the head, choose the blue dragon scales as a body, Said the design is derived from foshan origin, nien and the story of the lion dance, the brief content for people with lion dancing with joy to dance (xia is one of the) scared away want to destroy the village nian (New Year’s eve), and then using the method of lion dance celebrating festival, a player with two against players, it corresponds to the lion dance and nian against, a symbol of the festival will come, Create the atmosphere of traditional Chinese festivals, and Chinese red elements. The game design, very satisfied, I personally think that own designing on the basis of the original repeated transformation, from the foundation of the snake, the double snake against, to double against more than food, and then to finally xia to dance, lion dance and nian fate, fate in the New Year lantern, and not only to join a lot of their own design, A lot of Chinese red elements, but also solved the program running cost, background blocks and body food overlapping printing flicker problem, and in the final product really created a “New Year flavor”, which is the biggest harvest of my game design.

 

 

Six, core source code:


// MySnake.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "stdio.h"
#include "resource.h"
#include "time.h"
#include <mmsystem.h>
#include <string.h>
#pragma comment(lib,"winmm.lib")
#define MAX_LOADSTRING 100
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_MYSNAKE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);
	if(! InitInstance (hInstance, nCmdShow)) {return FALSE;
	}
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MYSNAKE);
	while (GetMessage(&msg, NULL, 0.0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;
	wcex.cbSize = sizeof(WNDCLASSEX); 
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_MYSNAKE);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_MYSNAKE;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
	return RegisterClassEx(&wcex);
}

// Frame coefficient
HDC hdc,mdc,bufdc;
int row=20;
int col=25;
int kk = 0;
int heightT = 200;
HBITMAP bg,bg2,pi1,pi2, food,pn[2];/ / map
#define  WIDTH 30
#define  HEIGHT 30
#define  MAXSIZE  50
// Body data structure
struct Snake
{
   POINT m_pos[MAXSIZE];
   int m_direction;
   int len;
};
Snake m_snake,m_snake2;// Year of the Lion Dance
#define NUMBER 15 // The amount of food
POINT m_food[NUMBER];// Food generation
int foods[30] [25],body[30] [25];// Prevent duplicate printing

// Initialize the food
void foodbegin() {
	for (int i = 0; i < NUMBER; i++) {
		m_food[i].x = rand() %(col-1) +1;
		m_food[i].y = rand() %(row-1) +1;
		foods[m_food[i].x][m_food[i].y] = 1; }}// Food updates
void generatefood(int i)
{
	srand((unsigned)time(NULL));
	do {
		m_food[i].x = rand() % (col - 1) + 1;
		m_food[i].y = rand() % (row - 1) + 1;
	} while (foods[m_food[i].x][m_food[i].y] == 1);    // Avoid food repetition
	foods[m_food[i].x][m_food[i].y] = 1;
}

// The body coefficient is initialized
void init_snake()
{
	// The lion dance body is initialized
	m_snake.len=3;
	m_snake.m_pos[0].x=1;
	m_snake.m_pos[0].y=5;
	m_snake.m_direction=1;
	for(int n=1; n<MAXSIZE; n++) { m_snake.m_pos[n].x=-1;
		m_snake.m_pos[n].y=-1;
	}
	// Year beast body initialization
	m_snake2.len = 3;
	m_snake2.m_pos[0].x =1;
	m_snake2.m_pos[0].y =row-5;
	m_snake2.m_direction = 1;
	for (int n = 1; n < MAXSIZE; n++)
	{
		m_snake2.m_pos[n].x = -1;
		m_snake2.m_pos[n].y = -1;
	}
	foodbegin();
}

// Screen generated
void MyPaint(HDC hdc)
{
	// Enter effect
	kk++;
	
	// Body position coefficient
	memset(body, 0, sizeof(body));
	for (int ii = m_snake.len; ii > -1; ii--) 
		body[m_snake.m_pos->x][m_snake.m_pos->y] = 1;
	for (int ii = m_snake2.len; ii > -1; ii--) 
		body[m_snake2.m_pos->x][m_snake2.m_pos->y] = 1;
	
	// Background plate is generated
	HBRUSH hbr=CreateSolidBrush(RGB(220.205.50));
	SelectObject(hdc,hbr);
	for(int y=1; y<row; y++)for (int x = 1; x < col; x++)
			if(foods[x][y]! =1&&body[x][y]! =1)
				Rectangle(hdc,x*WIDTH,y*HEIGHT,(x+1)*WIDTH,(y+1)*HEIGHT);
	
	// Edge wall is generated
	HBRUSH hbr2 =CreateSolidBrush(RGB(255.0.0));
	SelectObject(hdc, hbr2);
	for (int y = 0; y <= row; y++)
		Rectangle(hdc, col*WIDTH, y*HEIGHT, (col + 1)*WIDTH, (y + 1)*HEIGHT);
	for (int y = 0; y <= row; y++)
		Rectangle(hdc, 0*WIDTH, y*HEIGHT, (0 + 1)*WIDTH, (y + 1)*HEIGHT);
	for (int x = 0; x < col; x++)
		Rectangle(hdc, x*WIDTH, row*HEIGHT, (x + 1)*WIDTH, (row + 1)*HEIGHT);
	for (int x = 0; x < col; x++)
		Rectangle(hdc, x*WIDTH, 0*HEIGHT, (x + 1)*WIDTH, (0 + 1)*HEIGHT);
	
	// Generate the right data bar
	HFONT font = CreateFont(30.0.0.0.0.0.0.0, GB2312_CHARSET, 0.0.0.0, TEXT("Regular script"));
	SelectObject(hdc, font);
	//SetBkMode(hdc, TRANSPARENT); // The background color is transparent
	char str1[8];
	sprintf(str1, "%4d km", m_snake.len);   // Lion dance score
	char str2[8];
	sprintf(str2, "%4d km", m_snake2.len);  // Year beast score
	TextOut(hdc, col*WIDTH + 50.90."Space:".6);
	TextOut(hdc, col*WIDTH + 50.120."Start/Start again".10);
	TextOut(hdc, col*WIDTH + 60, heightT, "Lion dance".4);
	TextOut(hdc, col*WIDTH + 80, heightT+40."Write".2);
	TextOut(hdc, col*WIDTH + 50, heightT+70."Please left -".6);
	TextOut(hdc, col*WIDTH + 80, heightT+100, str1, 8);
	TextOut(hdc, col*WIDTH + 60, heightT+200."Nian".4);
	TextOut(hdc, col*WIDTH + 80, heightT+240."W ".2);
	TextOut(hdc, col*WIDTH + 50, heightT+270."A S D ".6);
	TextOut(hdc, col*WIDTH + 80, heightT+300, str2, 8);
	SelectObject(mdc, bg2);
	BitBlt(hdc, col*WIDTH + 40.0.150.80, mdc, 0.0, SRCCOPY);  // Paste the theme image
	
	// Food generation
	for (int i = 0; i < NUMBER; i++) {
		SelectObject(mdc, food);
		BitBlt(hdc, m_food[i].x * WIDTH, m_food[i].y * HEIGHT, 30.30, mdc, 0.0, SRCCOPY);
	}

	// The lion dance body is generated
	HBRUSH hbrgreen=CreateSolidBrush(RGB(0.109.163));
	SelectObject(hdc,hbrgreen);
	for (int n = 1; n < m_snake.len; n++) {
		SelectObject(mdc, pi1);
		BitBlt(hdc, m_snake.m_pos[n].x * 30, m_snake.m_pos[n].y * 30.30.30, mdc, 0.0, SRCCOPY);
	}
	/* Rectangle(hdc,m_snake.m_pos[n].x*WIDTH,m_snake.m_pos[n].y*HEIGHT,(m_snake.m_pos[n].x+1)*WIDTH, (m_snake.m_pos[n].y+1)*HEIGHT); * /

	// Year beast body is generated
	HBRUSH hbrgreen2 = CreateSolidBrush(RGB(235.95.37));
	SelectObject(hdc, hbrgreen2);
	for (int n = 1; n < m_snake2.len; n++) {
		SelectObject(mdc, pi2);
		BitBlt(hdc, m_snake2.m_pos[n].x * 30, m_snake2.m_pos[n].y * 30.30.30, mdc, 0.0, SRCCOPY);
	}
	/* Rectangle(hdc, m_snake2.m_pos[n].x * WIDTH, m_snake2.m_pos[n].y * HEIGHT, (m_snake2.m_pos[n].x + 1) * WIDTH, (m_snake2.m_pos[n].y + 1) * HEIGHT); * /

	// Header generation
	SelectObject(mdc, pn[0]);
	BitBlt(hdc, m_snake.m_pos[0].x * 30, m_snake.m_pos[0].y * 30.30.30, mdc, 0.0, SRCCOPY);
	SelectObject(mdc, pn[1]);
	BitBlt(hdc, m_snake2.m_pos[0].x * 30, m_snake2.m_pos[0].y * 30.30.30, mdc, 0.0, SRCCOPY);
	
}

// The game starts again
void OnStart(HWND hWnd)
{
	// Initialize the food
	memset(foods, 0, sizeof(foods));

	// Snake data initialization
	init_snake();

	// Reset the timer
	SetTimer(hWnd, 1.100, NULL);
} 

// Window Settings
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	// Window initialization
   HWND hWnd;
   hInst = hInstance; 
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if(! hWnd) {return FALSE;
   }
   RECT crc,wrc;
   GetClientRect(hWnd,&crc);
   GetWindowRect(hWnd,&wrc);
   int borderwidth=(wrc.right-wrc.left)-(crc.right-crc.left);
   int borderheight=(wrc.bottom-wrc.top)-(crc.bottom-crc.top);
   SetWindowPos(hWnd,NULL,0.0.950+borderwidth,630+borderheight,SWP_NOMOVE);
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   // Handle is given
   hdc=GetDC(hWnd);
   mdc = CreateCompatibleDC(hdc);
   bufdc = CreateCompatibleDC(hdc);

   // Import the material
   pn[0] = (HBITMAP)LoadImage(NULL, "H1.bmp", IMAGE_BITMAP, 30.30, LR_LOADFROMFILE);
   pn[1] = (HBITMAP)LoadImage(NULL, "H2.bmp", IMAGE_BITMAP, 30.30, LR_LOADFROMFILE);
   pi1 = (HBITMAP)LoadImage(NULL, "pi1.bmp", IMAGE_BITMAP, 30.30, LR_LOADFROMFILE);
   pi2 = (HBITMAP)LoadImage(NULL, "pi2.bmp", IMAGE_BITMAP, 30.30, LR_LOADFROMFILE);
   bg = (HBITMAP)LoadImage(NULL, "bg.bmp", IMAGE_BITMAP, 333.179, LR_LOADFROMFILE);
   bg2 = (HBITMAP)LoadImage(NULL, "bg2.bmp", IMAGE_BITMAP, 150.80, LR_LOADFROMFILE);
   food = (HBITMAP)LoadImage(NULL, "shi.bmp", IMAGE_BITMAP, 30.30, LR_LOADFROMFILE);

   // Play background music
   PlaySound("bgm.wav", NULL, SND_FILENAME | SND_ASYNC);

   return TRUE;
}

// Admission setup
void start() 
{
	SelectObject(mdc, bg2);
	BitBlt(hdc, col*WIDTH + 40.0.150.80, mdc, 0.0, SRCCOPY);
	SelectObject(mdc, bg);
	BitBlt(hdc, 300.200.333.3179, mdc, 0.0, SRCCOPY);
}

// The game function
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int n;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	
	// Enter the opening screen
	if (kk == 1) 
		start();

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			switch (wmId)
			{
				case IDM_EXIT:
				   DestroyWindow(hWnd);         // Exit the game
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
			case WM_KEYDOWN:
				switch(wParam)
				{
				// The opening is reopened
				case 32:
					OnStart(hWnd);
					break;
				// Lion dance control
				case VK_UP:
					m_snake.m_direction=0;
					break;
				case VK_RIGHT:
					m_snake.m_direction=1;
					break;
				case VK_DOWN:
					m_snake.m_direction=2;
					break;
				case VK_LEFT:
					m_snake.m_direction=3;
					break;
				// Year beast control
				case 87:
					m_snake2.m_direction = 0;
					break;
				case 68:
					m_snake2.m_direction = 1;
					break;
				case 83:
					m_snake2.m_direction = 2;
					break;
				case 65:
					m_snake2.m_direction = 3;
					break;
				}
				break;
				case WM_TIMER:
					// The lion dances forward
					for( n=m_snake.len-1; n>=1; n--) m_snake.m_pos[n]=m_snake.m_pos[n-1];
					if(0==m_snake.m_direction)
						m_snake.m_pos[0].y=m_snake.m_pos[0].y-1;
					if(1==m_snake.m_direction)
						m_snake.m_pos[0].x=m_snake.m_pos[0].x+1;
					if(2==m_snake.m_direction)
						m_snake.m_pos[0].y=m_snake.m_pos[0].y+1;
					if( 3==m_snake.m_direction)
						m_snake.m_pos[0].x=m_snake.m_pos[0].x-1;

					// The year beast advances
					for (n = m_snake2.len - 1; n >= 1; n--)
						m_snake2.m_pos[n] = m_snake2.m_pos[n - 1];
					if (0 == m_snake2.m_direction)
						m_snake2.m_pos[0].y = m_snake2.m_pos[0].y - 1;
					if (1 == m_snake2.m_direction)
						m_snake2.m_pos[0].x = m_snake2.m_pos[0].x + 1;
					if (2 == m_snake2.m_direction)
						m_snake2.m_pos[0].y = m_snake2.m_pos[0].y + 1;
					if (3 == m_snake2.m_direction)
						m_snake2.m_pos[0].x = m_snake2.m_pos[0].x - 1;

					// Catch food decision
					for (int i = 0; i < NUMBER; i++) {
						if(m_snake.m_pos[0].x==m_food[i].x&&m_snake.m_pos[0].y==m_food[i].y)
						{
							m_snake.len++;  // Body growth
							foods[m_food[i].x][m_food[i].y] = 0;    // Prevent the food reprint coefficient from going to zero
							generatefood(i);  // Food updates
						}
						if (m_snake2.m_pos[0].x == m_food[i].x && m_snake2.m_pos[0].y == m_food[i].y)
						{
							m_snake2.len++;
							foods[m_food[i].x][m_food[i].y] = 0; generatefood(i); }}// The lion dance is dead
					for (int i = 1; i < m_snake2.len; i++)
					{
						if (m_snake.m_pos[0].x == m_snake2.m_pos[i].x && m_snake.m_pos[0].y == m_snake2.m_pos[i].y)
						{
							KillTimer(hWnd, 1);
							if (IDYES == MessageBox(hWnd, "Nian wins first Place."."Tip", MB_YESNO))
								OnStart(hWnd);
							else
								PostQuitMessage(0); }}if(m_snake.m_pos[0].x>col||m_snake.m_pos[0].y>row||m_snake.m_pos[0].x<0||m_snake.m_pos[0].y<0)
					{
						KillTimer(hWnd,1);
						if(IDYES == MessageBox(hWnd, "Nian wins first Place."."Tip",MB_YESNO))
							OnStart(hWnd);
						else
							PostQuitMessage(0);
					}

					// Year animal death judgment
					for (int i = 1; i < m_snake.len; i++)
					{
						if (m_snake2.m_pos[0].x == m_snake.m_pos[i].x && m_snake2.m_pos[0].y == m_snake.m_pos[i].y)
						{
							KillTimer(hWnd, 1);
							if (IDYES == MessageBox(hWnd, "Lion Dance wins first Prize."."Tip", MB_YESNO))
								OnStart(hWnd);
							else
								PostQuitMessage(0); }}if (m_snake2.m_pos[0].x > col || m_snake2.m_pos[0].y > row || m_snake2.m_pos[0].x < 0 || m_snake2.m_pos[0].y < 0)
					{
						KillTimer(hWnd,1);
						if (IDYES == MessageBox(hWnd, "Lion Dance wins first Prize."."Tip", MB_YESNO))
							OnStart(hWnd);
						else
							PostQuitMessage(0);
					}

					// Screen refresh
					hdc=GetDC(hWnd);
					MyPaint(hdc);
					break;
		
		case WM_PAINT:
			// Screen generated
			hdc = BeginPaint(hWnd, &ps);
			MyPaint(hdc);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
 
Copy the code

 

New entry, seeking a wave of attention, continue to update quality original content.