基本思路
加载木鱼图片,两个尺寸(大和小)各加载到两个IMAGE变量中,在窗口中绘制图片,然后死循环监测鼠标操作,如果点击就把画面清楚,然后绘制尺寸小的图片,在窗口合适位置绘制文字(比如“功德+1”),“功德数”变量++;如果是鼠标左键松开,就清除画面,绘制尺寸大的图像
代码实现
#include<easyx.h>
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
initgraph(400, 260,0);
IMAGE picture1,picture2;
ExMessage msg;
int score = 0;
char score_c[10] = {'0'};
loadimage(&picture1, "0.jpg", 400, 260);
loadimage(&picture2, "0.jpg", 380, 240);
putimage(0, 0, &picture1);
BeginBatchDraw();
settextstyle(20, 0, "楷体");
settextcolor(WHITE);
setbkmode(TRANSPARENT);
outtextxy(320, 0, _T("功德:"));
outtextxy(370, 0, _T(score_c));
while (true) {
FlushBatchDraw();
msg = getmessage(EX_MOUSE);
if (msg.message == WM_LBUTTONDOWN) {
cleardevice();
putimage(10, 10, &picture2);
outtextxy(10, 0, _T("功德+1"));
score++;
sprintf_s(score_c, "%d", score);
}
else if (msg.message == WM_LBUTTONUP) {
cleardevice();
putimage(0, 0, &picture1);
}
outtextxy(320, 0, _T("功德:"));
outtextxy(370, 0, score_c);
}
getmessage(EX_CHAR);
EndBatchDraw();
closegraph();
return 0;
}