引用EasyX库的C语言编程:类似贪吃蛇的鼠标移动效果
程序员文章站
2022-04-07 19:47:07
...
引用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;
}
下一篇: upc 真假鉴定 思维+模拟