求一个用C语言写的扫雷代码!
要求有扫雷的全部功能以及详细注释转一个:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include<time.h>
showmine();
setmine(int x);
printmine();
countmine(int rowno, int colno);
char rowhead="1 2 3 4 5 6\n";
char rowhead2="----------- \n";
char rowone="1|\xf \xf \xf \xf \xf \xf \n";
char rowtwo="2|\xf \xf \xf \xf \xf \xf \n";
char rowthree="3|\xf \xf \xf \xf \xf \xf \n";
char rowfour= "4|\xf \xf \xf \xf \xf \xf \n";
char rowfive= "5|\xf \xf \xf \xf \xf \xf \n";
char rowsix="6|\xf \xf \xf \xf \xf \xf \n";
int mines={{0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0},
{0,0,1,0,0,1,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0},
{0,0,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0},
};
int countstep=0;
int n=10;
main()
{
int i,j;
int flag=1;
showmine();
setmine(n);
printmine();
while(flag)
{
printf("\n请输入位置:行号,列号:");
scanf("%d,%d", &i,&j);
if (mines==1)
{
printmine();
printf("\n BOOM!!!");
getchar();
getchar();
flag=0;
}
else
{
countmine(i,j);
system("cls");
showmine();
if(countstep==36-n)
{
printf("You Wind!");
getchar();
getchar();
flag=0;
}
}
}
}
countmine(int rowno, int colno)
{
int count;
int i,j;
i=rowno;
j=colno;
count=mines+mines+mines+mines
+mines+mines+mines+mines;
switch(i)
{
case 1:
rowone=(char)(count+48);
break;
case 2:
rowtwo=(char)(count+48);
break;
case 3:
rowthree=(char)(count+48);
break;
case 4:
rowfour=(char)(count+48);
break;
case 5:
rowfive=(char)(count+48);
break;
case 6:
rowsix=(char)(count+48);
break;
}
countstep=countstep+1;
}
showmine()
{
printf(rowhead);
printf(rowhead2);
printf(rowone);
printf(rowtwo);
printf(rowthree);
printf(rowfour);
printf(rowfive);
printf(rowsix);
}
setmine(int x)
{int i,j,k;
for(i=1;i<=6;i++)
for(j=1;j<=6;j++)
mines=0;
srand(time(0));
for(k=1;k<=x;)
{
i=rand()%6+1;
j=rand()%6+1;
if(mines!=1)
mines=1;
else
continue;
k++;
}
}
printmine()
{int i,j,k;
system("cls");
for(i=1;i<=6;i++)
{for(j=1;j<=6;j++)
if( mines==1)
printf("%c ",15);
else
printf("%c ",2);
printf("\n");}
} 小甲鱼的二师兄 发表于 2015-5-17 20:13
转一个:
你这个扫雷不正宗,我以前就看过了,我要的是弄个新的界面想win7里面的那种,不过还是谢谢了 混个鱼币走人:big:big:big 你这个网上搜的吧? 回锅丶肉 发表于 2015-6-6 00:21
混个鱼币走人
早在网上看过了 回锅丶肉 发表于 2015-6-6 00:21
混个鱼币走人
算了也不打算用c写了,送你鱼币吧!
页:
[1]