鼠标判断不正常(待填的坑)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<easyx.h> //图形库,绘制图形,输出文字
#include<stdlib.h>
#include<time.h>
/*
* 别踩白块:c+easyx
*
*/
#define INTERVAL 100 //标题高度
#define GRID_W 100 //块的宽度
#define GRID_H 150 //块的高度

//定义数组,存储黑块
int flags[4] = { 0 };

//统计成功点了多少个黑块
int gCount = 0;
void init()
{
//设置随机数种子
srand((unsigned int)time(NULL));
//随机生成黑块
for (int i = 0; i < 4; i++)
{
flags[i] = rand() % 4;//0,1,2,3
}

}

void draw()
{
const char* title = "别踩白块儿";
setlinestyle(PS_SOLID, 2);
//线条的颜色,默认是白色
setlinecolor(BLACK);

for (int i = 0; i < 5; i++)
{
//画横线
line(0, i * 150 + INTERVAL, 400, i * 150 + INTERVAL);
//画竖线
line(100 * i, INTERVAL, i * 100, 700);
}

//设置文字颜色,样式
settextcolor(BLACK);
settextstyle(38, 0, "Arial");
//输出标题(居中)
int spaceW = (getwidth() - textwidth(title)) / 2;
int spaceH = (INTERVAL - textheight(title)) / 2;
outtextxy(spaceW, spaceH, title);

//绘制黑块
setfillcolor(BLACK);
for (int i = 0; i < 4; i++)
{
//求出黑块的左上角坐标;
int x = flags[i] * GRID_W;
int y = i * GRID_H + INTERVAL;
if (i == 3)
{
setfillcolor(RGB(156, 156, 156));

}
//绘制一个矩形
fillrectangle(x, y, x + GRID_W, y + GRID_H);
}

//输出分数
settextstyle(26, 0, "微软雅黑");
char score[30] = { 0 };
sprintf_s(score,"Score:%d", gCount);

outtextxy(20, 40, score);
}

//处理鼠标点击
bool mousePressMsg(ExMessage* msg)
{
//获取下标为2的黑块的坐标
int x = flags[2]*GRID_W;
int y = 2 * GRID_H + INTERVAL;

//判断是不是点击的下标为2的黑块
if (msg->x > x && x < x + GRID_W && msg->y > y && msg->y < y + GRID_H)
{
//黑块从上往下移动
for (int i = 3; i > 0; i--)
{
flags[i] = flags[i - 1];
}
flags[0] = rand() % 4;//随机生成
gCount++;
printf("你点击了正确的黑块\n");

}
else
{
// printf("%s", __FUNCTION__); /* 输出是什么函数 */
return false;
}
return true;

}

//
void gameOverHit(int w, int h)
{
setlinecolor(GREEN);
setfillcolor(RGB(93, 107, 153));

//画一个矩形
int spaceH = (getwidth() - w) / 2;
int spaceV = (getwidth() - h) / 2;
fillrectangle(spaceH, spaceV, spaceH + w, spaceV + h);
int mid_w = (spaceH + w) / 2;
int mid_h = (2*spaceV+h) / 2;
outtextxy(mid_w, mid_h, "lyx is sb");
}
int main()
{
//1.黑窗口,来个图形窗口
initgraph(400, 700, EX_SHOWCONSOLE);
//设置背景颜色
setbkcolor(WHITE);
cleardevice();
setbkmode(TRANSPARENT);
init();

draw();

//游戏主循环
bool isDone = false;
while (!isDone)
{
//消息(鼠标)处理
ExMessage msg = { 0 };
if (peekmessage(&msg))
{
//按ESC退出游戏
switch (msg.message)
{
case WM_KEYDOWN:
if (msg.vkcode == VK_ESCAPE)
{
printf("quit\n");
isDone = true;
}
break;
case WM_LBUTTONDOWN:
if (!mousePressMsg(&msg))
{
isDone = true;
};
default:
break;
}
}
//绘制
BeginBatchDraw();//清除缓存
cleardevice();//清屏
draw();

EndBatchDraw();
}
gameOverHit(200,150);
/*
//设置线条的样式
setlinestyle(PS_SOLID, 3);
//设置线条yanse
setlinecolor(RED);
//绘制线条
line(0, 0, 640, 480);


//设置填充颜色
setfillcolor(GREEN);
//绘制矩形
rectangle(50, 50, 50 + 250, 50 + 50);
fillrectangle(50, 160, 50 + 250, 60 + 50);
*/

getchar();
return 0;
}