拼图游戏
2008-03-08 12:26:29 来源:WEB开发网核心提示:经过修改并加了注解运行程序后,会产生9个数字,拼图游戏,当人把数字拼成1 2 34 5 67 8 9你就过关了,很简单的
经过修改并加了注解
运行程序后,会产生9个数字,当人把数字拼成 1 2 3 4 5 6 7 8 9 你就过关了,很简单的。 #include<math.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>
#define left 0x4b
#define right 0x4d
#define down 0x50
#define esc 0x01
#define up 0x48
#define col 4
#define row 3
int a[9]=;
int board[3][3];//面板
int k,m;//9的坐标
int get_key(void);
void Draw9(int x,int y,char s[]);//显示方格9
void Draw(int x,int y,char s[]);//显示其它方格
main()
{
int gdriver=VGA,gmode=VGAHI,errorcode;
int i,j,key,dec=9,temp,temp1;
char *s[]=;
initgraph(&gdriver,&gmode,"d:\tc");
errorcode=graphresult();
if(errorcode!=0)
{PRintf("the graph error:%s",grapherrormsg(errorcode));
getch();
printf("press any key to halt:");
exit(1);
} /*将个数字随机放在9个格子里*/ for(i=0;i<3;i++)
for(j=0;j<3;j++)
{temp=rand()%dec;dec--;
board[i][j]=a[temp];
for(temp1=temp;temp1<dec;temp1++)
a[temp1]=a[temp1+1];
}
setcolor(15);
rectangle(198,148,351,301);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
}
while(1)
{while(bioskey(1)==0);
key=get_key();
switch(key)
{case up:if(k>0)
{board[k][m]=board[k-1][m];
board[k-1][m]=9;
k--;
Draw9((col+m)*50,(row+k)*50,s[board[k][m>);
Draw((col+m)*50,(row+k+1)*50,s[board[k+1][m>);
if(judge()){printf("you win!!!,press any key to exit");getch();exit(0); } }
break;
case down:if(k<2)
{
board[k][m]=board[k+1][m];
board[k+1][m]=9;
k++;
Draw9((col+m)*50,(row+k)*50,s[board[k][m>);
Draw((col+m)*50,(row+k-1)*50,s[board[k-1][m>);
if(judge()){printf("you win!!!,press any key to exit");getch();exit(0);}
}
break;
case left:if(m>0)
{
board[k][m]=board[k][m-1];
board[k][m-1]=9;
m--;
Draw9((col+m)*50,(row+k)*50,s[board[k][m>);
Draw((col+m+1)*50,(row+k)*50,s[board[k][m+1>);
if(judge()){printf("you win!!!,press any key to exit");getch();exit(0);}
}
break;
case right:if(m<2)
{board[k][m]=board[k][m+1];
board[k][m+1]=9;
m++;
Draw9((col+m)*50,(row+k)*50,s[board[k][m>);
Draw((col+m-1)*50,(row+k)*50,s[board[k][m-1>);
if(judge()){printf("you win!!!,press any key to exit");getch();exit(0);}
}
break;
case esc:exit(0);
}
}
}
int get_key(void)
{union REGS reg;
reg.h.ah=0;
int86(0x16,?,?);
return(reg.h.ah);
}
void Draw9(int x,int y,char s[])/* x, y为左上角坐标sizex,sizey为长和宽*/
{int sizx=50-1;
int sizy=50-1;
setcolor(0);/*这里最好用灰色*/
line(x,y,x+sizx-1,y);
line(x,y+1,x+sizx-2,y+1);
line(x,y,x,y+sizy-1);
line(x+1,y,x+1,y+sizy-2);
setcolor(8);/*这里最好用深灰色*/
line(x+1,y+sizy,x+sizx,y+sizy);
line(x+2,y+sizy-1,x+sizx,y+sizy-1);
line(x+sizx-1,y+1,x+sizx-1,y+sizy);
line(x+sizx,y+2,x+sizx,y+sizy);
setcolor(15);/*这里最好用白色*/
putpixel(x,y+sizy,3);
putpixel(x+1,y+sizy-1,3);
putpixel(x+sizx,y,3);
putpixel(x+sizx-1,y+1,3);
setfillstyle(1, 7);/*这里最好用灰色,设置填充模式*/
bar(x+2,y+2,x+sizx-2,y+sizy-2);setcolor(0);
setcolor(0);
settextboardify(CENTER_TEXT,CENTER_TEXT);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
outtextxy(x+25,y+25,s);
}
void Draw(int x,int y,char s[])/* x, y为左上角坐标sizex,sizey为长和宽*/
{int sizx=50-1;
int sizy=50-1;
setcolor(15);/*这里最好用白色*/
line(x,y,x+sizx-1,y);
line(x,y+1,x+sizx-2,y+1);
line(x,y,x,y+sizy-1);
line(x+1,y,x+1,y+sizy-2);
setcolor(8);/*这里最好用深灰色*/
line(x+1,y+sizy,x+sizx,y+sizy);
line(x+2,y+sizy-1,x+sizx,y+sizy-1);
line(x+sizx-1,y+1,x+sizx-1,y+sizy);
line(x+sizx,y+2,x+sizx,y+sizy);
setcolor(7);/*这里最好用灰色*/
putpixel(x,y+sizy,3);
putpixel(x+1,y+sizy-1,3);
putpixel(x+sizx,y,3);
putpixel(x+sizx-1,y+1,3);
setfillstyle(1, 7);/*这里最好用灰色,设置填充模式*/
bar(x+2,y+2,x+sizx-2,y+sizy-2);setcolor(0);
setcolor(0);
settextboardify(CENTER_TEXT,CENTER_TEXT);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
outtextxy(x+25,y+25,s);
}
int judge()
{if((board[0][0]==1)&&(board[0][1]==2)&&(board[0][2]==3)&&(board[1][0]==4)&&(board[1][1]==5)&&(board[1][2]==6)&&(board[2][0]==7)&&(board[2][1]==8)&&(board[2][2]==9))
return 1;
esle return 0;
}
[]
- ››游戏网《千军破》名将养成秘籍
- ››拼图场景华丽变身 美图秀秀新版试用美图秀秀
- ››游戏定位成牵引Android发展的火车头
- ››游戏的知识时代?传媒大佬闯入游戏江湖
- ››游戏场景烘焙贴图制作
- ››游戏植物大战僵尸 iPhone 版9天销售额超100万美元...
- ››游戏开发包 iPhone cocos2d 初体验
- ››游戏三维怪物施法特效教程
- ››游戏人生Silverlight(2) - 趣味钢琴[Silverlight ...
- ››游戏人生Silverlight(3) - 打苍蝇[Silverlight 2....
- ››游戏人生Silverlight(4) - 连连看[Silverlight 2....
- ››游戏人生Silverlight(5) - 星际竞技场[Silverligh...
更多精彩
赞助商链接