简单的小拼图源码.doc
上传人:qw****27 上传时间:2024-09-12 格式:DOC 页数:4 大小:31KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

简单的小拼图源码.doc

简单的小拼图源码.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

拼图源码#include<graphics.h>#include<conio.h>#include<stdio.h>#defineWIDTH550#defineHEIGHT600intarr[3][3]={4,1,9,7,2,8,6,3,5,};intarr1[3][3]={1,2,3,4,5,6,7,8,9};voidshowpicture();voidplaygame();voidiswin();charname[10];intflag=1;voidmain(){initgraph(WIDTH,HEIGHT);while(flag){showpicture();playgame();iswin();}while(1){showpicture();}getch();closegraph();return;}voidshowpicture(){IMAGEimg;for(inti=0;i<3;++i){for(intj=0;j<3;++j){sprintf(name,"%d.jpg",arr[i][j]);getimage(&img,name);putimage(j*180,i*150,&img);}}}voidplaygame(){inttemp=0;charstr=getch();for(intx=0;x<3;++x){for(inty=0;y<3;++y){if(arr[x][y]==9){switch(str){case's':if(x>0){temp=arr[x][y];arr[x][y]=arr[x-1][y];arr[x-1][y]=temp;return;}break;case'w':if(x<2){temp=arr[x][y];arr[x][y]=arr[x+1][y];arr[x+1][y]=temp;return;}break;case'd':if(y>0){temp=arr[x][y];arr[x][y]=arr[x][y-1];arr[x][y-1]=temp;return;}break;case'a':if(y<2){temp=arr[x][y];arr[x][y]=arr[x][y+1];arr[x][y+1]=temp;return;}break;}}}}}voidiswin(){intcount=0;for(inti=0;i<3;++i){for(intj=0;j<3;++j){if(arr[i][j]==arr1[i][j]){++count;}else{return;}}}if(count==9){showpicture();setcolor(WHITE);setfont(40,40,"");outtextxy(100,480,"恭喜过关!");flag=0;}}