拼图

嗨又和大家  见面了 不知道 这一次的代码 你们喜不喜欢

下面这个是图片素材希望喜欢


下面这个是 自定义 库文件

#pragma once 
#include <stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<time.h>
#include<conio.h>


#pragma comment(lib,"winmm.lib")


#define Window_width  800 //窗口宽
#define Window_high 600 //窗口的高


#define wide 100//图片大小


#define Line Window_high/wide//行数
#define List (Window_width-200) /wide


int mep[Line][List];
int temporary[Line*List];//临时一维数组
IMAGE Background_map ,artwork_master,artwork_yuantu;
IMAGE Image_segmentation[Line*List];


int Mousex, Mousey;
int subscriptx, subscripty;


int judge();
void intermediary(void);
void  output(void);
void control(void);

源代码

/*********************************************
项    目:拼图
作    者:零起点
时    间:2017年3月29日
版    本:2.0
功    能:鼠标操作
编译环境:VS2015 graphics.h
**********************************************/
#include"gete.h"


int main(void)
{
initgraph(Window_width, Window_high);//创建窗口的大小
mciSendString(L"open ./音乐/格桑花的祝愿.mp3 alias BGM", NULL, NULL, NULL);
mciSendString(L"play BGM repeat", NULL, NULL, NULL);
loadimage(&Background_map, L"./time/背景底图.jpg", Window_width, Window_high);//把背景图加载到 Background_map 里面 图片大小为窗口大小
loadimage(&artwork_master, L"./time/原图.jpg", Window_width -200, Window_high);//所要拼图的照片加载到  artwork_master
loadimage(&artwork_yuantu, L"./time/原图.jpg", 180, 180);
putimage(0, 0, &Background_map);
MOUSEMSG Mouse;

intermediary();
output();
while (1)
{
Mouse = GetMouseMsg();
switch (Mouse.uMsg)
{
case WM_LBUTTONDOWN:
if (Mouse.x >= List*wide && Mouse.y >= wide / 2 && Mouse.x <= Window_width - 10 && Mouse.y <= wide / 2 + 30)
control();
else if (Mouse.x >= List*wide  && Mouse.y >= wide / 2 + 40 && Mouse.x <= Window_width - 10 && Mouse.y <= wide / 2 + 70)
putimage(0, 0, &artwork_master);
else if (Mouse.x >= List*wide  && Mouse.y >= wide / 2 + 80 && Mouse.x <= Window_width - 10 && Mouse.y <= wide / 2 + 110)
MessageBox(NULL, L"鼠标操作!!!", L"提示", MB_OK);
else if (Mouse.x >= List*wide  && Mouse.y >= wide / 2 + 120 && Mouse.x <= Window_width - 10 && Mouse.y <= wide / 2 + 150)
return 0;
break;
}
}
// control();
getchar();
closegraph();//关闭窗口
}


void  intermediary(void)
{
srand((unsigned int)time(NULL));//生成随机种子
int size = Line*List;//为生成随机图片 
int n = 0;
for (int i = 0; i < Line*List; i++)
temporary[i] = i;//给一维数组赋值
for (int i = 0; i < Line; ++i)
{
for (int j = 0; j < List; ++j)
{
int t = rand() % size;
mep[i][j] = temporary[t];
for (int g = t; g < size - 1; ++g)
{
temporary[g] = temporary[g + 1];
}
--size;
}
}


SetWorkingImage(&artwork_master);
for (int i = 0; i < Line; ++i)
{
for (int j = 0; j < List; ++j)
{
getimage(&Image_segmentation[n], i*wide, j*wide, wide, wide);
n++;
}
}
SetWorkingImage(NULL);
loadimage(&Image_segmentation[Line*List - 1], L"./time/beijing.jpg", wide, wide);
putimage((List-1)*wide, (Line-1)*wide, &Image_segmentation[Line*List - 1]);


setbkmode(TRANSPARENT);
rectangle(List*wide, wide / 2, Window_width-10, wide / 2 + 30);
outtextxy(List*wide, wide / 2 + 10, L"    开   始   游   戏");
rectangle(List*wide, wide / 2+40, Window_width-10, wide / 2 + 70);
outtextxy(List*wide, wide / 2 + 90, L"    游   戏   规   则");
rectangle(List*wide, wide / 2+80, Window_width-10, wide / 2 + 110);
outtextxy(List*wide, wide / 2 + 50, L"    查   看   原   图");
rectangle(List*wide, wide / 2 + 120, Window_width - 10, wide / 2 + 150);
outtextxy(List*wide, wide / 2 + 130, L"   退   出   游   戏");
}
void  output(void)
{
for(int i=0;i<Line;++i)
for (int j = 0; j < List; ++j)
{
putimage(i*wide, j*wide, &Image_segmentation[mep[i][j]]);
}
putimage(wide*List+10, wide / 2 + 160, &artwork_yuantu);
}


void control(void)
{
MOUSEMSG Mouse;
int a = 1;
for(int i= 0;i<Line;++i)
for (int j = 0; j < List; ++j)
{
if (mep[i][j] == Line*List - 1)
{
subscriptx = i;
subscripty = j;
}
}
while (a)
{
Mouse = GetMouseMsg();
Mousex = Mouse.x / wide;
Mousey = Mouse.y / wide;
switch (Mouse.uMsg)
{
case WM_LBUTTONDOWN:
if (Mousex >= 0 && Mousex <= Line - 1)
{
if (Mousex - 1 == subscriptx&&subscripty == Mousey || Mousex + 1 == subscriptx &&subscripty == Mousey
|| Mousex == subscriptx && subscripty == Mousey - 1 || Mousex == subscriptx&&subscripty == Mousey + 1)
{
mep[subscriptx][subscripty] = mep[Mousex][Mousey];
mep[Mousex][Mousey] = Line*List - 1;
subscriptx = Mousex;
subscripty = Mousey;
}
}
output();
break;
}
if (judge())
{
MessageBox(NULL, L"你赢了 !!", L"提示", MB_OK);
a = 0;
}
}
}


int judge()
{
int n = 0;
for (int i = 0; i < Line; ++i)
{
for (int j = 0; j < List; ++j)
{
if (mep[i][j] == temporary[n])
n++;
else
break;
}
}
if (n == Line*List)
return 1;
else
return 0;
}

如果不知道什么意思  就请加QQ群514500989   大家一起讨论  谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值