```c
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define ROW 12
#define COL 12
char Mine_board[ROW][COL];
char Show_board[ROW][COL];
```c
void Clear();
void Menu();
void Choose_menu();
void Game();
void Init_board(char board[ROW][COL]);
void Display(char board[ROW][COL]);
void Set_mine(char board[ROW][COL]);
void Set_show(char board[ROW][COL],int row,int col);
int Judge(char board[ROW][COL]);
void Clear()
{
printf("\033c");
}
void Menu()
{
printf("******************************\n");
printf("********** 1.play **********\n");
printf("********** 0.exit **********\n");
printf("******************************\n");
}
void Choose_menu()
{
int input=0;
while(input!=1)
{
scanf("%d",&input);
switch(input)
{
case(1):
{
Clear();
printf("game start\n");
break;
}
case(0):
{
Clear();
printf("game over\n");
break;
}
default:
{
printf("error\n");
break;
}
}
}
}
void Game()
{
srand((unsigned int)time(NULL));
Init_board(Mine_board);
Init_board(Show_board);
Display(Show_board);
Set_mine(Mine_board);
int row=0,col=0;
while(Judge(Show_board))
{
scanf("%d %d",&row,&col);
if(row>ROW-2||row<1||col>COL-2||col<1)
{
printf("Error!Please press again!\n");
}
else
{
Clear();
if(Mine_board[row][col]=='*')
{
printf("Sorry,you lost!\n");
Display(Mine_board);
break;
}
else
{
Set_show(Show_board,row,col);
Display(Show_board);
}
}
if(Judge(Show_board)==0)
{
printf("Congratulation!You win!\n");
}
}
}
void Init_board(char board[ROW][COL])
{
int row,col;
for(row=0;row<ROW;row++)
{
for(col=0;col<COL;col++)
{
board[row][col]=' ';
}
}
}
void Display(char board[ROW][COL])
{
int row,col;
for(row=0;row<ROW-1;row++)
{
printf("%2d ",row);
for(col=0;col<COL-1;col++)
{
if(row==0&&col>0)
{
printf("|%2d ",col);
}
else if(row>0&&col>0)
{
printf("| %c ",board[row][col]);
}
}
printf("\n");
if(row<ROW-2)
{
int x;
for(x=0;x<COL-2;x++)
{
printf("---|");
}
printf("---\n");
}
}
}
void Set_mine(char board[ROW][COL])
{
int x=ROW;
while(x>0)
{
int row=rand()%(ROW-2)+1;
int col=rand()%(COL-2)+1;
if(board[row][col]!='*')
{
board[row][col]='*';
x--;
}
}
}
void Set_show(char board[ROW][COL],int row,int col)
{
int m=-1,n=-1,count=0;
for(m=-1;m<2;m++)
{
for(n=-1;n<2;n++)
{
if(Mine_board[row+m][col+n]=='*')
{
count++;
}
}
}
Show_board[row][col]=count+'0';
}
int Judge(char board[ROW][COL])
{
int x=0,y=0;
for(x=1;x<ROW-1;x++)
{
for(y=1;y<COL-1;y++)
{
if(Show_board[x][y]==' '&&Mine_board[x][y]==' ')
return 1;
}
}
return 0;
}
int main()
{
while(1)
{
Menu();
Choose_menu();
Game();
}
return 0;
}