数据结构扫雷实训源代码.docx

上传人:b****7 文档编号:9671635 上传时间:2023-02-05 格式:DOCX 页数:74 大小:27.86KB
下载 相关 举报
数据结构扫雷实训源代码.docx_第1页
第1页 / 共74页
数据结构扫雷实训源代码.docx_第2页
第2页 / 共74页
数据结构扫雷实训源代码.docx_第3页
第3页 / 共74页
数据结构扫雷实训源代码.docx_第4页
第4页 / 共74页
数据结构扫雷实训源代码.docx_第5页
第5页 / 共74页
点击查看更多>>
下载资源
资源描述

数据结构扫雷实训源代码.docx

《数据结构扫雷实训源代码.docx》由会员分享,可在线阅读,更多相关《数据结构扫雷实训源代码.docx(74页珍藏版)》请在冰豆网上搜索。

数据结构扫雷实训源代码.docx

数据结构扫雷实训源代码

所需头文件和头文件的安装方法请到网上

下载

/**************************************************************************************/

/*著作权所有者:

*/

/*文件名:

扫雷.cpp*/

/*内容:

对排好序的文件进行检索*/

/*作成日期作者:

*/

/*修正日期作者:

*/

/**************************************************************************************/

#include

#include

#include

#include

#include

#include

#include

pthread_tthread[2];

pthread_mutex_tmut;

MOUSEMSGm;

int*a;//一个用于分配空间的指针

intpost;//初始化不同等级雷的数量

intsize;//不同等级分配不同内存空间

intshenyumine;//记录剩余雷的数量

int*two;//记录每个位置旁边有多少雷,0代表无雷,9代表当前位置是雷

int*twotemp;//记录当前位置是否被鼠标左键点击

int*numflags;//记录当前位置鼠标右键是否点击

inttimerm=0;//内置计时器的分钟数

inttimers=0;//内置计时器的秒数

intcontroltime=0;

intcenter_x=0;

intcenter_y=0;

intclasssign=1;//定义游戏等级且默认状态为低级

intleftdownsign;//记录

intgameend;//标记游戏是否结束

intreturnend=0;//标记是否点击返回按钮

intrestarttimer;//标记是否点击重新开始以清零计时器

clock_ttime_start,time_stop;//标记游戏开始到结束所用时间

floatscore;//记录游戏分数

intlable;//标签控制鼠标点击时对应的不同页面

IMAGEp;//读取图片鼠标未指向状态

IMAGEp11;//读取图片鼠标指向状态

IMAGEp1;//读取图片鼠标未指向状态

IMAGEp21;//读取图片鼠标指向状态

IMAGEp2;

IMAGEp31;

IMAGEp3;

IMAGEp41;

IMAGEc;

IMAGEc1;

IMAGEc11;

IMAGEc2;

IMAGEc21;

IMAGEc3;

IMAGEc31;

IMAGEf;

IMAGEs;

IMAGEt;

IMAGErestarttemp;//读取图片鼠标未指向状态

IMAGErestart;

IMAGEreturtemp;//读取图片鼠标指向状态

IMAGEretur;

IMAGEzero;//读取旁边地雷数量图标

IMAGEone;

IMAGEtwo1;

IMAGEthree;

IMAGEfour;

IMAGEfive;

IMAGEsix;

IMAGEseven;

IMAGEeight;

IMAGEmine;//读取地雷

IMAGEshenyu;//隐蔽计数显示

IMAGEsuremax;

IMAGEsuremaxtemp;

IMAGEclearrecod;

IMAGEclearrecodtemp;

voidmouseaction();

voidginterface();

voidmianinterface();

voidrandom();

voidaddtion();

voidautoshow(intx,inty,inttemp);

voidautoshowtemp(intx,inty,inttemp,inta,intb,intc);

voidshowshenyuminenum();

voidmaxscore(intscore,intsign);

voidthread_create();

voidclearrecodfile();

voidsuregameend();

voidautoshowtip(intx,inty,inttemp);

voidautoshowtemptiptemp(intx,inty,inttemp,inta,intb,intc);

voidautoshowreturntemp(intx,inty,inttemp,inta,intb,intc);

voidautoshowreturn(intx,inty,inttemp);

intscanautoshow(intx,inty,inttemp);

intscanautoshowtemp(intx,inty,inttemp,inta,intb,intc);

voidgetclass()//得到游戏等级函数

{

putimage(270,80,&c);

putimage(270,80,&c1);

putimage(270,175,&c2);

putimage(270,285,&c3);

lable=2;

mouseaction();

}

voidmouseaction()//鼠标控制游戏界面

{

intsign=0;//标记鼠标该函数是否退出

intflagsnum=0;//插入旗帜的个数

inttemp;//记录当前等级下雷盘的行数

if(classsign==1)

{

temp=6;

}

if(classsign==2)

{

temp=9;

}

if(classsign==3)

{

temp=10;

}

while

(1)

{

m=GetMouseMsg();//得到鼠标当前状态如没有状态则等待

switch(m.uMsg)

{

caseWM_MOUSEMOVE:

//移动鼠标

if(lable==1)//主界面

{

if(m.x>=270&&m.x<=370&&m.y>=80&&m.y<=115)//确定鼠标当前位置是否在相应范围内

{

putimage(270,80,&p11);

}

if(((m.x<270||m.x>370)||(m.y<80||m.y>115)))

{

putimage(270,80,&p);

}

if(m.x>=270&&m.x<=370&&m.y>=220&&m.y<=255)

{

putimage(270,220,&p21);

}

if(((m.x<270||m.x>370)||(m.y<220||m.y>255)))

{

putimage(270,220,&p3);

}

if(m.x>=270&&m.x<=370&&m.y>=150&&m.y<=185)

{

putimage(270,150,&p41);

}

if(((m.x<270||m.x>370)||(m.y<150||m.y>185)))

{

putimage(270,150,&p2);

}

if(m.x>=270&&m.x<=370&&m.y>=290&&m.y<=325)

{

putimage(270,290,&p31);

}

if(((m.x<270||m.x>370)||(m.y<290||m.y>325)))

{

putimage(270,290,&p1);

}

}

if(lable==2)//等级设置

{

if(m.x>=270&&m.x<=370&&m.y>=80&&m.y<=120)

{

putimage(270,80,&c11);

}

if(((m.x<270||m.x>370)||(m.y<80||m.y>120)))

{

putimage(270,80,&c1);

}

if(m.x>=270&&m.x<=370&&m.y>=175&&m.y<=215)

{

putimage(270,175,&c21);

}

if(((m.x<270||m.x>370)||(m.y<175||m.y>215)))

{

putimage(270,175,&c2);

}

if(m.x>=270&&m.x<=370&&m.y>=285&&m.y<=325)

{

putimage(270,285,&c31);

}

if(((m.x<270||m.x>370)||(m.y<285||m.y>325)))

{

putimage(270,285,&c3);

}

}

if(lable==3)//游戏界面

{

if(m.x>=130&&m.x<=250&&m.y>=400&&m.y<=440)

{

putimage(130,400,&restarttemp);

}

if(((m.x<130||m.x>250)||(m.y<400||m.y>440)))

{

putimage(130,400,&restart);

}

if(m.x>=350&&m.x<=470&&m.y>=400&&m.y<=440)

{

putimage(350,400,&returtemp);

}

if(((m.x<350||m.x>470)||(m.y<400||m.y>440)))

{

putimage(350,400,&retur);

}

}

if(lable==4)//最高记录界面

{

if(m.x>=150&&m.x<=270&&m.y>=400&&m.y<=430)

{

putimage(150,400,&suremaxtemp);

}

else

{

putimage(150,400,&suremax);

}

if(m.x>=380&&m.x<=500&&m.y>=400&&m.y<=430)

{

putimage(380,400,&clearrecodtemp);

}

else

{

putimage(380,400,&clearrecod);

}

}

break;

caseWM_LBUTTONDOWN:

//点击鼠标左键

if(classsign==1)

{

temp=6;

}

if(classsign==2)

{

temp=9;

}

if(classsign==3)

{

temp=10;

}

if(lable==1)//主界面

{

if(m.x>=270&&m.x<=370&&m.y>=220&&m.y<=255)

{

sign=1;

getclass();

}

if(m.x>=270&&m.x<=370&&m.y>=150&&m.y<=185)

{

maxscore(2,1);

sign=1;

}

if(m.x>=270&&m.x<=370&&m.y>=80&&m.y<=115)

{

sign=1;

returnend=0;

time_start=clock();//记录游戏开始时间

thread_create();//创建多线程为实现计时器和游戏同时运行

//random();

//addtion();

//ginterface();

}

if(m.x>=270&&m.x<=370&&m.y>=290&&m.y<=325)

{

sign=1;

//closegraph();

exit(0);

}

}

if(lable==2)//等级界面

{

if(m.x>=270&&m.x<=370&&m.y>=80&&m.y<=120)

{

classsign=1;

lable=1;

loadimage(NULL,"images\\maininterface.jpg");

putimage(270,80,&p);

putimage(270,290,&p1);

putimage(270,150,&p2);//输出获取的图像

putimage(270,220,&p3);

mouseaction();

}

if(m.x>=270&&m.x<=370&&m.y>=175&&m.y<=215)

{

classsign=2;

lable=1;

loadimage(NULL,"images\\maininterface.jpg");

putimage(270,80,&p);

putimage(270,290,&p1);

putimage(270,150,&p2);//输出获取的图像

putimage(270,220,&p3);

mouseaction();

}

if(m.x>=270&&m.x<=370&&m.y>=285&&m.y<=325)

{

classsign=3;

lable=1;

loadimage(NULL,"images\\maininterface.jpg");

putimage(270,80,&p);

putimage(270,290,&p1);

putimage(270,150,&p2);//输出获取的图像

putimage(270,220,&p3);

mouseaction();

}

}

if(lable==3)//游戏界面

{

if(m.x>=150&&m.x<=(150+temp*30)&&m.y>=50&&m.y<=(50+temp*30)&&leftdownsign==0&&gameend==0)//判断鼠标位置并确定游戏是否结束和当前位置是否被鼠标左键点击

{

//printf("%d%d%d\n",*(two+((m.x-150)/30)+((m.y-50)/30)*temp),(m.y-50)/30,((m.x-150)/30));

if(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)!

=9)

{

if(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

//putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&s);

autoshow(m.x,m.y,temp);

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==1&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&one);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==2&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&two1);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==3&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&three);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==4&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&four);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==5&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&five);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==6&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&six);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==7&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&seven);

}

elseif(*(two+((m.x-150)/30)+((m.y-50)/30)*temp)==8&&*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)==0)

{

*(twotemp+((m.x-150)/30)+((m.y-50)/30)*temp)=1;

putimage(((m.x-150)/30)*30+150,((m.y-50)/30)*30+50,&eight);

}

if(*(numflags+((m.x-150)/30)+((m.y-50)/30)*temp)==1)

{

*(numflags+((m.x-150)/30)+((m.y-50)/30)*temp)=0;

shenyumine++;//取消有雷状态重新计算雷德数量

showshenyuminenum();

suregameend();

}

}

else

{

time_stop=clock();//挖到地雷游戏结束计时器得到当前时间

for(inti=0;i

{

for(intj=0;j

{

if(*(two+temp*i+j)==9)

putimage(150+j*30,50+30*i,&mine);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1