假期在家重温了下C语言,下面直接给大家上代码!!
#include
#include
#include
#include
#include
#pragma comment(lib,“Winmm.lib”)
void meau()
{
initgraph(600, 600);
setbkcolor(RGB(150, 50, 50));
cleardevice();//刷新页面
setfillcolor(RED);
fillrectangle(200, 120, 400, 200);
fillrectangle(200, 300, 400, 380);
setbkmode(TRANSPARENT);
settextstyle(35,22,"");
outtextxy(200 + 10,120 + 23,"开始游戏");
outtextxy(200 + 10, 300 + 23, "退出游戏");
settextstyle(50, 32, "");
settextcolor(RGB(0,0,0));
outtextxy(140 + 10, 450 + 23, "晗哥制作!!");
MOUSEMSG m;
while (true)
{
m = GetMouseMsg();
if (m.x>=200&&m.x<=400&&m.y>=120&&m.y<=200)
{
setlinecolor(BLACKONWHITE);
rectangle(200 - 5, 120-5, 400+5, 200+5);
if (m.uMsg==WM_LBUTTONDOWN)
{
break;
}
}
else if (m.x >= 200 && m.x <= 400 && m.y >= 300 && m.y <= 380)
{
setlinecolor(BLACKONWHITE);
rectangle(200 - 5, 300 - 5, 400 + 5, 380+ 5);
if (m.uMsg==WM_LBUTTONDOWN)
{
exit(0);
}
}
else
{
setlinecolor(YELLOW);
rectangle(200 - 5, 300 - 5, 400 + 5, 380 + 5);
rectangle(200 - 5, 120 - 5, 400 + 5, 200 + 5);
}
}
closegraph();
}
void mainmeau()
{
initgraph(600, 600);
setbkcolor(WHITE);
loadingsource();
playgame();
closegraph();
}
loadimage(&img, "123456.jpg", 600, 600);
loadimage(&blank, "123.png", 200, 200);
用这种类型的语句进行加载图片
void drawmap()
{
for (int i= 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
int x = j * 200;
int y = i * 200;
switch (a2[i][j])
{
case 0:
case 1:
case 2:
putimage(x, y,200,200, &img, a2[i][j] * 200, 0);
break;
case 3:
case 4:
case 5:
putimage(x, y, 200, 200, &img, (a2[i][j]-3) * 200, 200);
break;
case 6:
case 7:
putimage(x, y, 200, 200, &img, (a2[i][j]-6) * 200, 400);
break;
case 8:
putimage(x, y, 200, 200, &blank, 0,0);
break;
default:
printf("程序数据出错,请勿擅自更改程序内容");
break;
}
}
}
}
void playgame()
{
MOUSEMSG m;
while (1)
{
drawmap();
int i, j = 0;
int mousei, mousej;
search(a2);
i = thispoint.i;
j = thispoint.j;
m = GetMouseMsg();
if (m.uMsg== WM_LBUTTONDOWN)
{
mousei=m.y / 200;
mousej= m.x / 200;
/*if (mousei == i + 1 && mousej == j|| mousei == i -1 && mousej == j || mousei == i && mousej == j+1 || mousei == i && mousej == j-1)*/
a2[i][j] = a2[mousei][mousej];
a2[mousei][mousej] = 8;
if (a2[0][0] == 0 && a2[0][1] == 1 && a2[0][2] ==2 && a2[1][0] == 3 && a2[1][1] == 4 && a2[1][2] == 5&& a2[2][0] == 6 && a2[2][1] == 7 && a2[2][2] == 8)
{
drawmap();
MessageBox(NULL, TEXT("点赞投币评论关注这个可爱的up主就可能在梦里得到我哟!"), TEXT("人家都被你看到了!"), MB_OK | MB_SETFOREGROUND);
break;
}
}
}
}
还有一句话,其实我还是昨天刚刚上线的一名B站up主,如果大家喜欢这个的话,我可能会在B站上出一些分享视频,一起来交流啊。
如果想看这个项目的完整代码,我上传的资源还没有过审核,可以点我的主页进行查找下载。