/* 扫雷 */
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main()
{
int times=0,mousey=0,mousex=0,posy=0,posx=0,hits=0,missed=0;
int num=0,row=0,col=0;
srand(time(0));
printf("请输入次数");
scanf("%d",×);
printf("***\n***\n***\n");
for(num=1;num<=times;num++)
{
mousey=rand()%3+1;
mousex=rand()%3+1;
do{
printf("请输入地雷所在的位置");
scanf("%d%d",&posy,&posx);
}while(posy<1||posy>3||posx<1||posx>3);
if(mousey==posy&&mousex==posx)
{
hits++;
}
else{missed++;}
for(row=1;row<=3;row++)
{
for(col=1;col<=3;col++)
{
if(row==posy&&col==posx)
{
printf("O");
}
else if(row==mousey&&col==mousex)
{
printf("X");
}
else
{
printf("*");
}
}
printf("\n");
}
if(mousey==posy&&mousex==posx)
{
printf("找到了地雷
");
}
else
{
printf("没找到地雷
");
}
printf("找到地雷%d次,没找到地雷%d次
",hits,missed);
}
return 0;
}
心得体会:程序编写的时候要细心认真,尽量减少编程的错误。编写完了记得认真检查。
我要赚赏金
