/*打地鼠游戏
*输入玩的次数
选择打的位置
确认是否打中
统计成绩
* */
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
printf("请输入玩的次数");
int num=0;
scanf("%d",&num);
int i=0,j=0;
int col=0;
int row=0;
int times=0;
int hits=0;
int miss=0;
printf("***\n***\n***\n");
for(times=1;times<=num;times++)
{
printf("请输入锤子的位置");
int ham_row=0;
int ham_col=0;
scanf("%d%d",&ham_row,&ham_col);
row=rand()%3+1;
col=rand()%3+1;
if(ham_row==row&&ham_col==col)
{
hits++;
}
else
{
miss++;
}
for(i=0;i<3;i++) //行号
{
for(j=0;j<3;j++) //列号
{
if(i==ham_row&&j==ham_col)
{
printf("0");
}
else if(i==row&&j==col)
{
printf("X");
}
else
{
printf("*");
}
}
printf("\n");
}
if(ham_row==row&&ham_col==col)
{
printf("打中了");
}
else
{
printf("未打中");
}
}
printf("您一共玩了%d次,其中打中了%d次,未打中%d次",num,hits,miss);
return 0;
}