原创C语言扫雷程序大作业代码.doc
文本预览下载声明
#includestdio.h
#includestdlib.h
#includetime.h
#define random(x) (rand()%x)
int n=0;//-------------------------------------------完成度判断
int bomb[12][12]={{},{},{},{},{},{},{},{},{},{},{},{},};//地雷分布(地雷1、无雷0)
int tru[10][10]={{},{},{},{},{},{},{},{},{},{}};//真相数组[truth](地雷数、地雷*、误判/、空白O)
int tbl[12][12]={{ ,X,1,2,3,4,5,6,7,8,9,10},
{Y,+,-,-,-,-,-,-,-,-,-,-},
{1,|,_,_,_,_,_,_,_,_,_,_},
{2,|,_,_,_,_,_,_,_,_,_,_},
{3,|,_,_,_,_,_,_,_,_,_,_},
{4,|,_,_,_,_,_,_,_,_,_,_},
{5,|,_,_,_,_,_,_,_,_,_,_},
{6,|,_,_,_,_,_,_,_,_,_,_},
{7,|,_,_,_,_,_,_,_,_,_,_},
{8,|,_,_,_,_,_,_,_,_,_,_},
{9,|,_,_,_,_,_,_,_,_,_,_},
{10,|,_,_,_,_,_,_,_,_,_,_}}; //棋盘数组[table](坐标系|-12、地雷数、红旗P、地雷*、爆炸X、误判/)
int main()//---------------------主函数
{
welcome();
do
{
game();
}
while (n=9);//未胜利,继续进行游戏
if(n==10)
printf(Mission succeed!\n);//全部地雷标记完成,胜利
else
printf(Mission failed!\n);//n=11,引爆地雷,失败
return 0;
}
int welcome()
{
int i,j,m,a,num;
printf(Hello,welcome to Bomb Hunter!\nFirst of all,please input the number of bombs(eg:30):\n);
scanf(%d,num);
printf(Now lets begin,good luck!\n);
srand((int)time(0));
for (m=0;mnum;)
{
a=random(100);//----------------------0到99生成随机数,取个位和十位
j=a%10+1;
i=(a-j)/10+1;
if(bomb[i][j]!=1)
{
bomb[i][j]=1;
m++;
}
}//------------------------------------地雷数组生成
printf(loading...\n);
updt_tru();//---------------tru生成
dspl();//-------------------打印棋盘
return 0;
}
int updt_tru()//---------------------------真相数组的生成[update_truth]
{
int e,f;
for(e=1;e11;e++)
for(f=1;f11;f++)
{
if(bomb[e][f]==1)
tru[e-1][f-1]=*;
else
tru[e-1][f-1]=_;
}
return 0;
}
int updt_tbl()//---------------------------------游戏中棋盘的更新
{
int i,j;
for (i=1;i11;i++)
显示全部