c语言连连看游戏.docx
- 文档编号:23798022
- 上传时间:2023-05-20
- 格式:DOCX
- 页数:22
- 大小:17.55KB
c语言连连看游戏.docx
《c语言连连看游戏.docx》由会员分享,可在线阅读,更多相关《c语言连连看游戏.docx(22页珍藏版)》请在冰豆网上搜索。
c语言连连看游戏
#include
#include
#include
#include
#include
#include
intb[10][10];
intx,y,x1,y1;staticintp=0,r=0;
charcursor[2],tail[2];
voidgotoxy(intx,inty)//输出坐标
{
COORDpos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
voidcolor(intb)//颜色函数
{
HANDLEhConsole=GetStdHandle((STD_OUTPUT_HANDLE));
SetConsoleTextAttribute(hConsole,b);
}
voidInit()//初始化界面
{
inti,j,a[10];
for(i=0;i<9;i++)
{
gotoxy(0,i);
color(11);
for(j=0;j<10;j++)
switch(rand()%10)
{
case0:
printf("★");b[i][j]=0;++a[0];continue;
case1:
printf("●");b[i][j]=1;++a[1];continue;
case2:
printf("■");b[i][j]=2;++a[2];continue;
case3:
printf("▲");b[i][j]=3;++a[3];continue;
case4:
printf("〓");b[i][j]=4;++a[4];continue;
case5:
printf("№");b[i][j]=5;++a[5];continue;
case6:
printf("♂");b[i][j]=6;++a[6];continue;
case7:
printf("#");b[i][j]=7;++a[7];continue;
case8:
printf("♀");b[i][j]=8;++a[8];continue;
case9:
printf("※");b[i][j]=9;++a[9];continue;
}
}
printf("\n");
for(i=0;i<10;i++)
{
if(a[i]%2!
=0)
switch(i)
{
case0:
printf("★");b[9][i]=0;continue;
case1:
printf("●");b[9][i]=1;continue;
case2:
printf("■");b[9][i]=2;continue;
case3:
printf("▲");b[9][i]=3;continue;
case4:
printf("〓");b[9][i]=4;continue;
case5:
printf("№");b[9][i]=5;continue;
case6:
printf("♂");b[9][i]=6;continue;
case7:
printf("#");b[9][i]=7;continue;
case8:
printf("♀");b[9][i]=8;continue;
case9:
printf("※");b[9][i]=9;continue;
}
else{printf("@");b[9][i]=10;}
}
gotoxy(8,4);
color(14);
switch(b[4][4])
{
case0:
printf("★");break;
case1:
printf("●");break;
case2:
printf("■");break;
case3:
printf("▲");break;
case4:
printf("〓");break;
case5:
printf("№");break;
case6:
printf("♂");break;
case7:
printf("#");break;
case8:
printf("♀");break;
case9:
printf("※");break;
}
cursor[0]=4;cursor[1]=4;
}
intway()//判断方法
{
inti,j,a;
if(y==0&&y1==0&&b[y][x]==b[y][x1])
return1;
if(x==9&&x1==9&&b[y][x]==b[y1][x1])
return1;
if(x+1==x1&&y==y1)
return1;
if(y==9&&y1==9&&b[y][x]==b[y1][x1])
return1;
if(x==0&&x1==0&&b[y][x]==b[y1][x1])
return1;
if(y+1==y1&&x==x1)return1;
if(y==y1)
{
for(i=x+1;i if(b[y][i]! =11)break; if(i==x1&&i! =x+1) return1; for(i=y-1;i>=-1;i--) { if(i==-1)return1; for(j=x;j<=x1;j++) if(b[i][j]! =11)break; if(j==x1+1)return1; if(b[i][x]! =11||b[i][x1]! =11) break; } for(i=y+1;i<=10;i++) { if(i==10)return1; for(j=x;j<=x1;j++) if(b[i][j]! =11)break; if(j==x1+1)return1; if(b[i][x]! =11||b[i][x1]! =11) break; } } if(x==x1) { for(i=y+1;i if(b[i][x]! =11)break; if(i! =y+1&&i==y1)return1; for(i=x-1;i>=-1;i--) { if(i==-1)return1; for(j=y;j if(b[j][i]! =11)break; if(j==y1+1) return1; if(b[y][i]! =11||b[y1][i]! =11)break; } for(i=x+1;i<=10;i++) { if(i==10)return1; for(j=y;j if(b[j][i]! =11)break; if(j==y1+1) return1; if(b[y][i]! =11||b[y1][i]! =11)break; } } if(y =x1) { for(i=y+1;i<=y1;i++) if(b[i][x]! =11||b[y1][x]! =11)break; if(i==y1+1) { for(j=x;j if(b[y1][j]! =11)break; if(j==x1)return1; } for(i=y+1;i { for(j=x;j<=x1;j++) if(b[i][j]! =11)break; if(j==x1+1) { for(a=i;a if(b[a][x1]! =11)break; if(a==y1&&a! =y+1&&a! =i)return1; } if(b[i][x]! =11) break; } for(i=x+1;i<=x1;i++) if(b[y][i]! =11||b[y][x1]! =11)break; if(i==x1+1) { for(j=y;j if(b[j][x1]! =11)break; if(j==y1)return1; } for(i=x+1;i { for(j=y;j<=y1;j++) if(b[j][i]! =11)break; if(j==y1+1) { for(a=i;a if(b[y1][a]! =11)break; if(a==x1&&a! =x+1&&a! =i) return1; } if(b[y][i]! =11)break; } if(b[y1][x]==11) { for(i=x1-1;i>=x;i--) if(b[y1][i]! =11)break; if(i==x-1) { for(j=x-1;j>=-1;j--) { if(j==-1)return1; for(a=y;a<=y1;a++) if(b[a][j]! =11)break; if(a==y1+1)return1; if(b[y][j]! =11||b[y1][j]! =11) break; } } for(i=y+1;i<=y1;i++) if(b[i][x]! =11)break; if(i==y1+1) { for(j=y1+1;j<=10;j++) { if(j==10)return1; for(a=x;a<=x1;a++) if(b[j][a]! =11)break; if(a==x1+1)break; if(b[j][x]! =11||b[j][x1]! =11) break; } } } if(b[y][x1]==11) { for(i=x+1;i<=x1;i++) if(b[y][i]! =11)break; if(i==x1+1) { for(j=x1+1;j<=10;j++) { if(j==10)return1; for(a=y;a<=y1;a++) if(b[a][j]! =11)break; if(a==y1+1)return1; if(b[y][j]! =11||b[y1][j]! =11) break; } } for(i=y1-1;i>=y;i--) if(b[i][x1]! =11)break; if(i==y-1) { for(j=y-1;j>=-1;j--) { if(j==-1)return1; for(a=x;a<=x1;a++) if(b[j][a]! =11)break; if(a==x1+1)return1; if(b[j][x]! =11||b[j][x1]! =11) break; } } } } if(y>y1&&x! =x1) { for(i=y-1;i>=y1;i--) if(b[i][x]! =11||b[y1][x]! =11)break; if(i==y1-1) { for(j=x;j if(b[y1][j]! =11)break; if(j==x1)return1; } for(i=y-1;i>y1;i--) { for(j=x;j<=x1;j++) if(b[i][j]! =11)break; if(j==x1+1) { for(a=i;a>y1;a--) if(b[a][x1]! =11)break; if(a==y1&&a! =y-1&&a! =i)return1; } if(b[i][x]! =11)break; } for(i=x+1;i<=x1;i++) if(b[y][i]! =11&&b[y][x1]! =11)break; if(i==x1+1) { for(j=y;j>y1;j--) if(b[j][x1]! =11)break; if(j==y1)return1; } for(i=x+1;i { for(j=y;j>=y1;j--) if(b[j][i]! =11)break; if(j==y1-1) { for(a=i;a if(b[y1][a]! =11)break; if(a==x1&&a! =x+1&&a! =i)return1; } if(b[y][i]! =11)break; } if(b[y][x1]==11) { for(i=x+1;i<=x1;i++) if(b[y][i]! =11)break; if(i==x1+1) { for(j=x1+1;j<=10;j++) { if(j==10)return1; for(a=y;a>=y1;a--) if(b[a][j]! =11)break; if(a==y1-1)return1; if(b[y1][j]! =11||b[y][j]! =11) break; } } for(i=y1+1;i<=y;i++) if(b[i][x1]! =11)break; if(i==y+1) { for(j=y+1;j<=10;j++) { if(j==10)return1; for(a=x1;a>=x;a--) if(b[j][a]! =11)break; if(a==x-1)return1; if(b[j][x]! =11||b[j][x1]! =11) break; } } } if(b[y1][x]==11) { for(i=y-1;i>=y1;i--) if(b[i][x]! =11)break; if(i==y1-1) { for(j=y1-1;j>=-1;j--) { if(j==-1)return1; for(a=x1;a>=x;a--) if(b[j][a]! =11)break; if(a==x-1)return1; if(b[j][x]! =11||b[j][x1]! =11) break; } } for(i=x1-1;i>=x;i--) if(b[y1][i]! =11)break; if(i==x-1) { for(j=x-1;j>=-1;j--) { if(j==-1)return1; for(a=y;a>=y1;a--) if(b[a][j]! =11)break; if(a==y1-1)return1; if(b[y1][j]! =11||b[y][j]! =11) break; } } } } return0; } voidmove(charch)//方向控制 { staticintcount=0; memcpy(tail,cursor,2); switch(ch) { case'w': case'W': if(cursor[1]>0)cursor[1]--;break; case's': case'S': if(cursor[1]<9)cursor[1]++;break; case'a': case'A': if(cursor[0]>0)cursor[0]--;break; case'd': case'D': if(cursor[0]<9)cursor[0]++;break; case'j': case'J': { if(count==1) {p=1;count=0;} else {r=1;count=1;} } break; } } voiddraw()//光标移动 { staticinta=0,c=0,d=0,e=0; if(r==1) { a=cursor[0];c=cursor[1]; gotoxy(a*2,c); color(12); switch(b[c][a]) { case0: printf("★");break; case1: printf("●");break; case2: printf("■");break; case3: printf("▲");break; case4: printf("〓");break; case5: printf("№");break; case6: printf("♂");break; case7: printf("#");break; case8: printf("♀");break; case9: printf("※");break; case10: printf("@");break; case11: color(0);printf("");break; } r++; } if(p) { d=cursor[0];e=cursor[1]; gotoxy(d*2,e); color(12); switch(b[e][d]) { case0: printf("★");break; case1: printf("●");break; case2: printf("■");break; case3: printf("▲");break; case4: printf("〓");break; case5: printf("№");break; case6: printf("♂");break; case7: printf("#");break; case8: printf("♀");break; case9: printf("※");break; case10: printf("@");break; case11: color(0);printf("");break; } } if(tail[0]! =a||tail[1]! =c) { gotoxy(tail[0]*2,tail[1]);color(11); switch(b[tail[1]][tail[0]]) { case0: printf("★");break; case1: printf("●");break; case2: printf("■");break; case3: printf("▲");break; case4: printf("〓");break; case5: printf("№");break; case6: printf("♂");break; case7: printf("#");break; case8: printf("♀");break; case9: printf("※");break; case10: printf("@");break; case11: color(0);printf("");break; } } if(cursor[0]! =a||cursor[1]! =c) { gotoxy(cursor[0]*2,cursor[1]); color(14); switch(b[cursor[1]][cursor[0]]) { case0: printf("★");break; case1: printf("●");break; case2: printf("■");break; case3: printf("▲");break; case4: printf("〓");break; case5: printf("№");break; case6: printf("♂");break; case7: printf("#");break; case8: printf("♀");break; case9: printf("※");break; case10: printf("@");break; case11: printf("□");break; } } if(a>d) { x1=a;x=d; y1=c;y=e; } elseif(a==d) { x=a;x1=d; if(c>e) {y=e;y1=c;} else{y=c;y1=e;} } else { x=a;x1=d; y=c;y1=e; } if(p&&r) { if(way()&&b[c][a]==b[e][d]) { gotoxy(a*2,c);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 连连 游戏