C言语完成简略单纯扫雷

2020-02-01 12bet 阅读

  //应用二维数组来表现地图,此处需求2个二维数组,第一个二维数组表现地雷的雷阵,第二个二维数组表现用户看到的地图

  //365bet地图大年夜小9*9;然则二维数组11*11

  #define _CRT_SECURE_NO_WARNINGS

  #include

  #include

  #define MINE_COUNT 10

  #define ROW 9

  #define COL 9

  char show_map[ROW + 2][COL + 2];

  char mine_map[ROW + 2][COL + 2];

  int Menu(){

  int choice=-1;

  printf("************************\n");

  printf("* 欢迎离开365bet游戏 *\n");

  printf("* 请您选择 *\n");

  printf("* 1.末尾游戏 *\n");

  printf("* 2.离开游戏 *\n");

  printf("************************\n");

  while (1){

  scanf("%d", &choice);

  if (choice==1)

  {

  return 1;

  break;

  }

  else if (choice==2)

  {

  exit(2);

  }

  else

  {

  printf("输入正当,请从新输入!\n");

  continue;

  }

  }

  }

  void Init(){ //初始化 布雷

  srand(time(0));

  memset(mine_map, '0', (ROW + 2)*(COL + 2));

  memset(show_map, '*', (ROW + 2)*(COL + 2));

  int count=MINE_COUNT;

  int row=-1;

  int col=-1;

  while (count>=0){

  row=rand() % ROW + 1;

  col=rand() % COL + 1;

  if (show_map[row][col]=='*')

  {

  mine_map[row][col]='1';

  count--;

  continue;

  }

  }

  }

  void Print(){ // 1 2 3 4 5 6 7 8 9

  printf(" "); // -----------------

  for (int col=1; col <=COL; col++) // 01 | | | | | | | | |

  { // -----------------

  printf(" %d ", col);

  }

  printf("\n ---------------------------\n");

  for (int row=1; row <=ROW; row++)

  {

  printf("%02d ", row);

  printf(" |%c |%c |%c |%c |%c |%c |%c |%c |%c |\n", show_map[row][1], show_map[row][2], show_map[row][3], show_map[row][4], show_map[row][5],

  show_map[row][6], show_map[row][7], show_map[row][8], show_map[row][9]);

  printf(" ---------------------------\n");

  }

  }

  char MineBoom(){

  printf(" ");

  for (int col=1; col <=COL; col++)

  {

  printf(" %d ", col);

  }

标签: