https://www.myziyuan.com/
- erpang666
- #include”e69da5e887aae799bee5baa631333262363032stdio.h”#include”conio.h”#include”stdlib.h”#include”dos.h”#include”time.h” int a[16+1][30+1];/*数组用来存放地雷和数字的 */多出一个是用来控制边界的 int flag1,flag2;/*长宽调整标志*/ int color_flag=1,lei_number=10,high=8,width=8,face_flag=1; struct time1/*调用时间函数*/ {unsigned char ti_min; unsigned char ti_hour; unsigned charti_hund; unsigned char ti_sec;}t; void rect() { /*本模块的功能是在C界面上画边框,以增加C的友好性和可观性*/ int i; textcolor(14); textbackground(color_flag); clrscr();/*设置字体和背景颜色*/ gotoxy(1,2);putchar(201);/*左上角*/ for(i=1;i<79;i++) {gotoxy(i+1,2);putchar(205);}/*直线*/ putchar(187);/*右上角*/ for(i=2;i<23;i++) {gotoxy(80,i+1);putchar(186);}/*直线*/ gotoxy(80,24);putchar(188);/*右下角*/ for(i=1;i<79;i++) {gotoxy(i+1,24);putchar(205);}/*竖线*/ gotoxy(1,24);putchar(200);/*右上角*/ for(i=2;i<23;i++) {gotoxy(1,i+1);putchar(186);}/*竖线*/ gotoxy(30,1);cprintf(“WELCOMETO SAOLEI!”); gotoxy(28,25);cprintf(“COPYRIGHT---LANGCY---2002”);} void rect_s() { int i;/*根据长宽调整标志画边框*/ gotoxy(flag2-1,flag1-1);putchar(218); gotoxy(flag2+width*2-1,flag1-1);putchar(191); gotoxy(flag2-1,flag1+high);putchar(192); gotoxy(flag2+width*2-1,flag1+high);putchar(217); for(i=flag2;i<flag2+width*2-1;i++) {gotoxy(i,flag1-1);putchar(196); gotoxy(i,flag1+high);putchar(196);} for(i=flag1;i<flag1+high;i++) {gotoxy(flag2-1,i);putchar(179); gotoxy(flag2+width*2-1,i);putchar(179);}} void color()/*颜色选择*/ { char ch; rect(); gotoxy(25,6);cprintf(”This is the color table!”); gotoxy(30,8);cprintf(”1-black”); gotoxy(30,9);cprintf(”2-blue”); gotoxy(30,10);cprintf(”3-green”); gotoxy(30,11);cprintf(”4-bluesky”);gotoxy(30,12);cprintf(”5-red”); gotoxy(30,13);cprintf(”6-pink”); gotoxy(30,14); cprintf(”7-yellow”); gotoxy(30,15);cprintf(”8-gray”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the color numble:”); while(1) {ch=getch(); switch(ch) {case’1’: color_flag=0;cprintf(”black!”);break; case’2’: color_flag=1;cprintf(”blue!”);break; case’3’: color_flag=2;cprintf(”green!”);break; case’4’: color_flag=3;cprintf(”bluesky!”);break; case’5’: color_flag=4;cprintf(”red!”);break; case’6’: color_flag=5;cprintf(”pink!”);break; case’7’: color_flag=6;cprintf(”yellow!”);break; case’8’: color_flag=7;cprintf(”gray!”);break; case 27: main();break; case 13: main();break; default :break;}}} void size()/*选择大小*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the lei_size table!”); gotoxy(30,10);cprintf(”1--high=8,width=8”); gotoxy(30,11);cprintf(”2--high=8,width=16”); gotoxy(30,12);cprintf(”3--high=16,width=16”); go-toxy(30,13);cprintf(”4--high=16,width=20”); gotoxy(30,14);cprintf(”5--high=16,width=25”); go-toxy(30,15);cprintf(”6--high=16,width=30”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the lei_numble:”); while(1) {ch=getch(); switch(ch) { case’1’: high=8;width=8;cprintf(”high=8,width=8”);break; case’2’: high=8;width=16;cprintf(”high=8,width=16”);break; case’3’: high=16;width=16;cprintf(”high=16,width=16”);break; case’4’: high=16;width=20;cprintf(”high=16,width=20”);break; case’5’: high=16;width=25;cprintf(”high=16,width=25”);break; case’6’: high=16;width=30;cprintf(”high=16,width=30”);break; case 27: main();break; case 13: main();break; default :break; }}} void lei_num()/*选择雷的数目*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the lei_number table!”); gotoxy(30,10);cprintf(”1-10”); gotoxy(30,11);cprintf(”2-20”); gotoxy(30,12);cprintf(”3-40”); gotoxy(30,13);cprintf(”4-50”); gotoxy(30,14);cprintf(”5-80”); gotoxy(30,15);cprintf(”6-100”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the lei_numble:”); while(1) {ch=getch(); switch(ch) { case’1’: lei_number=10;cprintf(”10”);break; case’2’: lei_number=20;cprintf(”20”);break; case’3’: lei_number=40;cprintf(”40”);break; case’4’: lei_number=50;cprintf(”50”);break; case’5’: lei_number=80;cprintf(”80”);break; case’6’: lei_number=100;cprintf(”100”);break; case 27: main();break; case 13: main();break; default :break; }}} void face()/*选择图标*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the face table!”); gotoxy(30,10);cprintf(”1--smail face”); gotoxy(30,11);cprintf(”2--heart”); gotoxy(30,12);cprintf(”3--rectangle”); gotoxy(30,13);cprintf(”4--flower”); gotoxy(30,14);cprintf(”5--peach”); gotoxy(30,15);cprintf(”6--music”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the face:”); while(1) {ch=getch(); switch(ch) { case’1’:face_flag=1;printf(”smail face!”);break; case’2’: face_flag=3;printf(”heart!”);break; case’3’: face_flag=4;printf(”rectangle!”);break; case’4’: face_flag=5;printf(”flower!”);break; case’5’: face_flag=6;printf(”peach!”);break; case’6’: face_flag=14;printf(”music!”);break; case 27: main();break; case 13: main();break; default :break;}}} void fail()/*没有扫成功,重新再来*/ { int i,j,t3,t4; char ch; flag1=(23-high)/2+2; flag2=(80-2*width)/2; for(i=1,t3=flag1;i<high+1;i++,t3++) for(j=1,t4=flag2;j<width+1;j++,t4+=2){ gotoxy(t4,t3); if(a[i][j]==-1) putchar(15); elseprintf(”%d”,a[i][j]); } gotoxy(25,23);printf(”Do you want to continue? <y/n>”); ch=getch(); if(ch==’y’||ch==’Y’) saolei(); elsemain();} void succeed()/*扫雷成功,再来否*/ { char ch; gotoxy(30,22);cprintf(”Congradulation! Youwin!”); gotoxy(25,23);printf(”Do you want to continue? <y/n>”); ch=getch(); if(ch==’y’||ch==’Y’) saolei(); else main();} saolei()/*扫雷函数*/ { int i,j,countlei,left=lei_number,time_flag1,time_flag2; int t1=1,t2=1,lei_flag=0,t3,t4; char ch; rect(); flag1=(23-high)/2+2; flag2=(80-2*width)/2; for(i=0;i<high+1;i++) for(j=0;j<width+1;j++) a[i][j]=0;/*初始值*/ while(lei_flag<=lei_number) { t1=1+random(high);t2=1+random(width); if(a[t1][t2]! =-1) { a[t1][t2]=-1; lei_flag++;}}/*随机赋地雷*/ for(i=1;i<high+1;i++) for(j=1;j<width+1;j++) { if(a[i][j]! =-1) { countlei=0;/*由于上面已经考虑了边界,这里不需判断边界*/ if(a[i-1][j-1]==-1) countlei++; if(a[i-1][j]==-1) countlei++; if(a[i-1][j+1]==-1) countlei++;if(a[i][j-1]==-1) countlei++; if(a[i][j+1]==-1) countlei++; if(a[i+1][j-1]==-1) countlei++; if(a[i+1][j]==-1) countlei++; if(a[i+1][j+1]==-1) countlei++; a[i][j]=countlei; } }/*计算各个地区周围的地雷的数目*/ rect_s();/*画小边框*/ for(i=1,t3=flag1;i<high+1;i++,t3++) for(j=1,t4=flag2;j<width+1;j++,t4+=2) {gotoxy(t4,t3);putchar(face_flag);} gotoxy(4,3);cprintf(”Left:%3d”,left); gotoxy(70,3);cprintf(”Time:000”); gettime(&t);/*从系统中取出时间*/ time_flag1=(int)t.ti_min*60+(int)t.ti_sec; i=1;j=1; while(1)/*键盘操作*/ { /*72-up,75-left,77-right,80-down,27-esc,13-enter,32-space*/ gettime(&t); time_flag2=(int)t.ti_min*60+(int)t.ti_sec-time_flag1; gotoxy(68,3);cprintf(”Time:%3d”,time_flag2); gotoxy(flag2,flag1); ch=getch(); switch(ch) { case 72 : i--;flag1--; if(i<=0) {i++;flag1++;} /*判断越界*/ gotoxy(flag2,flag1); break; case 75 : j--;flag2-=2; if(j<=0) {j++;flag2+=2;} gotoxy(flag2,flag1); break; case 77 : j++;flag2+=2;if(j>width) {j--;flag2-=2;} gotoxy(flag2,flag1);break; case 80 : i++;flag1++; if(i>high) {i--;flag1--;} gotoxy(flag2,flag1); break; case 32 : if(a[i][j]==-1) { putchar(15);left--; if(left==0) succeed();go-toxy(4,3);cprintf(”Left:%3d”,left); gotoxy(flag2,flag1); } else fail(); break; case 13 : if(a[i][j]! =-1) { printf(”%d”,a[i][j]); gotoxy(flag2,flag1); } if(a[i][j]==-1) fail(); break; case 27 : main();break; default : break;}}} main()/*主函数*/ { char ch; rect(); gotoxy(25,7);printf(”This is the main menu!”); gotoxy(30,9);printf(”Enter-start!”); gotoxy(30,10);printf(”1--Choose the color!”); gotoxy(30,11);printf(”2--Choose the size!”); gotoxy(30,12);printf(”3--Choose the lei_number!”); gotoxy(30,13);printf(”4--Choose the face!”); gotoxy(30,14);printf(”ESC--exit!”); gotoxy(25,16);printf(”Please select what you want!”); while(1) {ch=getch(); switch(ch) {case’1’: color();break; case’2’: size();break; case’3’: lei_num();break; case’4’: face();break; case 27: rect(); gotoxy(30,13); printf(”Thank you ! Good Bye!”); getch(); exit(0);break; case 13: saolei();break; default :break;}}}
- 2021-03-25 19:30:01
- 织梦源码
- 普通版本WINDOS扫雷程序是将布雷和扫雷结合扫雷程序思想讲解 在我大二的时候就编写了一个扫雷程序,现在也有很多源程序下载,我不知道他们的算法是怎么样的,但我想我的算法应是最清晰和简单的。下面就来讲解我的扫雷程序思想。 首先我们在雷区上随机地放上雷,没有雷的地方被点击后就会显示一个数字表示它周围有几个雷,这是怎么实现的呢?我们可以把整个雷区看成一个二维数组a[i,j],如雷区: 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27 28 31 32 33 34 35 36 37 38 41 42 43 44 45 46 47 48 51 52 53 54 55 56 57 58我要知道a[34]周围有几个雷,就只有去检测 a[23],a[24],a[25] a[33], a[35] a[43],a[44],a[45]这8个雷区是否放上了雷,仔细观察它们成在数学关系。抽象出来就是:a[i,j]的雷的个数就是由 a[i-1,j-1],a[i-1,j],a[i-1,j+1] a[ i ,j-1], a[ i ,j+1] a[i+1,j-1],a[i+1,j],a[i+1,j+1] (如果超出边界再加以判断)这样的8个雷区决定的。 扫雷程序还会自动展开已确定没有雷的雷区。如果a[3,4]周围雷数为1,a[2,3]已被标示为地雷,那么a[24],a[25],a[33],a[35],a[43],a[44],a[45]将被展开,一直波及到不可确定的雷区。这也是实现的关键。我们可以把数组的元素设定为一个类对象,它们所属的类 因此普通版本WINDOS扫雷程序是将布雷和扫雷结合的
- 2021-02-12 15:13:43
- nij
- 求j2me扫雷简单源代码,j2me版扫雷源代码SosoImg运行环境 Win2000,WinXP,WinVista,Windows7软件大小 12.26KB软件授权 免费软件分类rar文件软件标签j2me更新时间 2008-07-10
- 2021-02-12 15:13:43