您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 广告经营 > C语言程序设计连连看
#includestdio.h#includestdlib.h#includetime.h#includeconio.h#includeiostreamusingnamespacestd;#includectimeintmai()//倒计时{for(inti=3;i=0;i--){longt=time(NULL);for(;;){longn=time(NULL);if(n!=t)break;}system(cls);coutendl;coutendl;cout离史上最卡哇依的游戏开始还有**i**秒哦!!!endl;}return0;}voidinit1();voidprint1();intexit1();voidinit2();voidprint2();intexit2();voidinit3();voidprint3();intexit3();voidnear1(inta,intb,inta1,intb1);charchessman[10][10];voidmain()//主函数{time_tstart,end,time;start=clock();mai();intd;coutendl;coutendl;coutendl;cout****************************************************************endl;cout****************************************************************endl;cout**亲,请选择适合您智商的级别:[1]低级[2]中级[3]登峰造极**endl;cout****************************************************************endl;cout****************************************************************endl;coutendl;coutendl;cout研发小组:QYQendl;cout请选择:***-;cind;cout-***endl;system(pause);switch(d){case1:init1();break;case2:init2();break;case3:init3();break;default:cout你个逗比;}intop;introw,line;introw2,line2;do{if(d==1)print1();elseif(d==2)print2();elseif(d==3)print3();printf(options:\n);printf(\t1.select\n);printf(\t2.restart\n);printf(\t3.sort\n);scanf(%d,&op);if(op==1){printf(不造亲第一个相中了谁呢:);scanf(%d%d,&line,&row);printf(再给他找个伴儿吧,亲:);scanf(%d%d,&line2,&row2);if(chessman[line][row]!=chessman[line2][row2]){printf(有缘无分呐!\n);system(pause);}elseif(line==line2&&row==row2){printf(有搞错哦,亲!!!\n);system(pause);}elseif(line=line2){near1(line,row,line2,row2);}else{near1(line2,row2,line,row);}}if(op==2){}if(op==3){main();}}while(exit1(),exit2(),exit3());system(pause);printf(\n\n\n\t\t哇呀!你好厉害!\n);end=clock();time=end-start;//这里的时间是计算机内部时间coutendltime:timeendl;system(pause);cout本次得分:98分!继续保持哦!endl;system(pause);}voidinit1()//4乘4矩阵{inti,j;inta[4]={0};srand(time(NULL));for(i=1;i4;i++)for(j=1;j5;j++){chessman[i][j]=rand()%4+65;if(chessman[i][j]==65)a[0]++;if(chessman[i][j]==66)a[1]++;if(chessman[i][j]==67)a[2]++;if(chessman[i][j]==68)a[3]++;}for(i=0;i4;i++){if(a[i]%2!=0)chessman[4][i+1]=i+65;elsechessman[4][i+1]=69;}}voidprint1(){inti,j;system(cls);printf(\t1234\n);for(i=0;i5;i++){printf(\t\n\t);for(j=0;j5;j++){printf(%4c,chessman[i][j]);if(j==4&&i!=0&&i!=5)printf(\t%d,i);}}printf(\n\n\n\n);}intexit1(){inti,j;for(i=0;i6;i++){for(j=0;j6;j++)if(chessman[i][j]!=0)return1;}return0;}voidinit2()//6乘6矩阵{inti,j;inta[6]={0};srand(time(NULL));for(i=1;i6;i++)for(j=1;j7;j++){chessman[i][j]=rand()%6+65;if(chessman[i][j]==65)a[0]++;if(chessman[i][j]==66)a[1]++;if(chessman[i][j]==67)a[2]++;if(chessman[i][j]==68)a[3]++;if(chessman[i][j]==69)a[4]++;if(chessman[i][j]==70)a[5]++;}for(i=0;i6;i++){if(a[i]%2!=0)chessman[6][i+1]=i+65;elsechessman[6][i+1]=71;}}voidprint2(){inti,j;system(cls);printf(\t123456\n);for(i=0;i8;i++){printf(\t\n\t);for(j=0;j8;j++){printf(%4c,chessman[i][j]);if(j==6&&i!=0&&i!=7)printf(\t%d,i);}}printf(\n\n\n\n);}intexit2(){inti,j;for(i=0;i8;i++){for(j=0;j8;j++)if(chessman[i][j]!=0)return1;}return0;}voidinit3()//8乘8矩阵{inti,j;inta[8]={0};srand(time(NULL));for(i=1;i8;i++)for(j=1;j9;j++){chessman[i][j]=rand()%8+65;//棋盘内容为A到Hif(chessman[i][j]==65)a[0]++;//记录A的个数if(chessman[i][j]==66)a[1]++;if(chessman[i][j]==67)a[2]++;if(chessman[i][j]==68)a[3]++;if(chessman[i][j]==69)a[4]++;if(chessman[i][j]==70)a[5]++;if(chessman[i][j]==71)a[6]++;if(chessman[i][j]==72)a[7]++;}for(i=0;i8;i++){if(a[i]%2!=0)chessman[8][i+1]=i+65;elsechessman[8][i+1]=73;}}voidprint3(){inti,j;system(cls);printf(\t12345678\n);for(i=0;i10;i++){printf(\t\n\t);for(j=0;j10;j++){printf(%4c,chessman[i][j]);if(j==9&&i!=0&&i!=9)printf(\t%d,i);}}printf(\n\n\n\n);}intexit3(){inti,j;for(i=0;i10;i++){for(j=0;j10;j++)if(chessman[i][j]!=0)return1;}return0;}voidnear1(inta,intb,inta1,intb1)//三种路径{intarow[2];intaline[2];intbrow[2];intbline[2];intstart=0,end=0;//临时两个点inti,j,n;//用于循环for(i=0;i2;i++)//初始化数组{arow[i]=a;brow[i]=a1;aline[i]=b;bline[i]=b1;}/////////////////////////////////////////(a,b)a列中有哪些列for(i=a+1;i10;i++){if(chessman[i][b]==0)arow[1]=i;//arow【1】A点a行向下向量elsebreak;}for(i=a-1;i=0;i--){if(chessman[i][b]==0)//arow【0】A点a行向上向量arow[0]=i;elsebreak;}////////////////////////////////////////////(a1,b1)a行中有哪些列for(i=a1+1;i10;i++){if(chessman[i][b1]==0)//brow[1]B点a1行向下向量brow[1]=i;elsebreak;}for(i=a1-1;i=0;i--){if(chessman[i][b1]==0)//brow[1]B点a1行向上向量brow[0]=i;elsebreak;}//////////////////////////////////////(a,b)b行有哪些列for(i=b+1;i10;i++){if(chessman[a][i]==0)//aline[1]A点b列向右向量aline[1]=i;elsebreak;}for(i=b-1;i=0;i--){if(chessman[a][i]==0)//aline[0]A点b列向左向量aline[0]=i;elsebreak;}/////////////////////////////(a1,b1)中b1列中有哪些行for(i=b1+1;i10;i++){if(chessman[a1][i]==0)//bline[1]B点b1列向左向量bline[1]=i;elsebreak;}for(i=b1-1;i=0;i--){if(chessman[a1][i]==0)//bline[1]B点b1列向右向量bline[0]=i;elsebreak;}///////////////////////////////////////关键算法////////////////////////////////////**********************情况一(a,b)(a1,b1)********************************
本文标题:C语言程序设计连连看
链接地址:https://www.777doc.com/doc-7123552 .html