The most complete explanation on the whole network of c++ writing tank war (memories of the same year)

C++ write tank battle

Project Preface

Proficiency in C language, C++ is required. Proficiency in various data types and data structures. Possess excellent document reading ability (design the use of EasyX graphics library), and have a beautiful and gentle girlfriend.

 Environmental preparation

I am using VS2022 here, and I also need to install the EasX graphics library. Installation tutorial icon-default.png?t=N6B9https://blog.csdn.net/m0_72703340/article/details/125968925

Initialization of the game window

 The first step is of course the initialization of the game.

We first use the interface provided by the easyX graphics library to initialize a drawing window. Define a macro to indicate the size of the window for subsequent secondary development

#define WIN_HEIGHT 650
#define WIN_WIDTH 650
initgraph(WIN_WIDTH, WIN_HEIGHT);

Then we define an initialization function.

 Import image material

In easyX, use IMAGE to represent image variables.

We define two variables, one is the logo and the other is the operation prompt.

	IMAGE imgLogo;
	IMAGE imgiLlustrate;

Then import the image using the loadimage function (you need to put the project material in the res folder first, otherwise the import will fail)

	loadimage(&imgLogo, "./res/logo.bmp");
	loadimage(&imgiLlustrate, "./res/illustrate.jpg");	

 Then draw the prompt button (I put the usage and definition of these functions at the end)


	setlinecolor(WHITE);
	setfillcolor(BLACK);

	fillrectangle(230, 200, 310, 240);
	settextstyle(25, 0, "宋体");
	outtextxy(240, 210, "说 明");
	
	fillrectangle(350, 200, 430, 240);
	outtextxy(360, 210, "开始");

Then paste the logo


	putimage(110, 20, &imgLogo);

Monitor and judge mouse messages

bool finished = true;
	while (finished) {
		mouseMsg = GetMouseMsg();
		switch (mouseMsg.uMsg)
		{
		case WM_MOUSEMOVE://鼠标移动
			if ((mouseMsg.x > 230 && mouseMsg.x < 310) &&( mouseMsg.y>200 && mouseMsg.y < 240)) 
			{
				putimage(150, 250, &imgiLlustrate);
			}
			else {
				solidrectangle(150, 250, 459, 550);
			}
			break;
		case WM_LBUTTONDOWN://左键down
			if ((mouseMsg.x > 350 && mouseMsg.x < 430) && (mouseMsg.y>200 && mouseMsg.y < 240)) {
				//to do
				cleardevice();	
				finished = true;
				break;
			}
		}
	}




Too tired to write here first

Guess you like

Origin blog.csdn.net/m0_72703340/article/details/132074669