欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

引用EasyX库的C语言编程:类似贪吃蛇的鼠标移动效果

程序员文章站 2022-04-07 19:47:07
...

引用EasyX库的C语言编程:类似贪吃蛇的鼠标移动效果
移动鼠标画白线,按鼠标左键画红线,按鼠标右键画绿线,滚动鼠标滚轮退出程序。

引用EasyX库的C语言编程:类似贪吃蛇的鼠标移动效果

#include<graphics.h>
struct MouseArray{
	int x;
	int y;
};
typedef struct MouseArray MA;
int main()
{
	initgraph(600, 600);
	setbkcolor(BLACK);
	cleardevice();
	MOUSEMSG msg;
	MA ma[100];
	int iarray;
	bool whether_full = false;
	setfillcolor(WHITE);

	//array initialization
	for (iarray = 0; iarray < 100; iarray++)
	{
		msg = GetMouseMsg();
		ma[iarray].x = msg.x;
		ma[iarray].y = msg.y;
		if (msg.mkLButton == true)
			setfillcolor(RED);
		if (msg.mkRButton == true)
			setfillcolor(GREEN);
		solidcircle(ma[iarray].x, ma[iarray].y, 3);
		setfillcolor(WHITE);
	}

	//main loop
	iarray = 0;
	while (msg.uMsg != WM_MOUSEWHEEL)
	{
		if (MouseHit())
		{
			msg = GetMouseMsg();
			iarray++;
			iarray = iarray % 100;
		}

		clearcircle(ma[iarray].x, ma[iarray].y, 3);
		ma[iarray].x = msg.x;
		ma[iarray].y = msg.y;
		if (msg.mkLButton == true)
			setfillcolor(RED);
		if (msg.mkRButton == true)
			setfillcolor(GREEN);
		solidcircle(ma[iarray].x, ma[iarray].y, 3);
		setfillcolor(WHITE);
		//Sleep(20);
	}
	closegraph();
	return 0;
}

相关标签: C语言 EasyX库