使用C语言编写一个扫雷游戏

  介绍

本篇文章为大家展示了使用C语言编写一个扫雷游戏,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

游戏。h

# pragma 一次   # include  & lt; stdio.h>   # include  & lt; string.h>   # include  & lt; time.h>   # include  & lt; windows.h>      # define  ROW  12   # define  COL  12   # define  NUMS  20      # pragma 警告(禁用:4996)      void 菜单();   void 游戏()

游戏。c

# include “game.h"      void 菜单()   {   ,printf (“# # # # # # # # # # # # # # # # # # # # # # # # # # # \ n");   ,printf (“# #, 1. play  2只Exit  # # \ n");   ,printf (“# # # # # # # # # # # # # # # # # # # # # # # # # # # \ n");   ,printf(“请输入#,“);   }   void  SetMines (char  [] (COL), int 行,int 坳)   {   ,int  num =, num;   ,while  (num), {   ,int  x =, rand (), %, 10, +, 1;   ,int  y =, rand (), %, 10, +, 1;   ,if (董事会[x] [y],==, & # 39; 0 & # 39;), {   ,董事会[x] [y],=, & # 39; 1 & # 39;;   ,num -;   ,}   ,}   }   int  GetNums (char  [] (COL), int 行,int ,上校,int  x,, int  y)   {   ,return 董事会[x 安康;1][y 安康;1],+,董事会[x 安康;1][y], + \   ,董事会[x 安康;1][+ y  1], +,董事会[x] [+ y  1], + \   ,董事会[x  +, 1] [+ y  1], +,董事会[+ x  1] [y], + \   ,董事会[x  +, 1] [y 安康;1],+,董事会[x] [y 安康;1],安康;8,*,& # 39;0 & # 39;;   }      void  ShowBoard (char  [] (COL), int 行,int 坳)   {   ,printf (“,“);   ,for  (int 小姐:=,1;,小姐:& lt;, col 作用;1;,我+ +),{   ,printf (“, % 2 d “,, i);   ,}   ,printf (“\ n");   ,printf (“- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ n");   ,for  (int 小姐:=,1;,小姐:& lt;, row 作用;1;,我+ +),{   ,printf (“% 2 d |“,, i);   ,for  (int  j =, 1,, j  & lt;, col 作用;1;,j + +), {   ,printf (“, % c  |“,,董事会[我][j]);   ,}   ,printf (“\ n");   ,printf (“- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ n");   ,}   }      void 游戏()   {   ,系统(“cls");   ,将srand (unsigned 长)时间(NULL));   (行),char  show_board (COL);   (行),char  mine_board (COL);      ,memset (show_board, & # 39; * & # 39;,, sizeof (show_board));   ,memset (mine_board, & # 39; 0 & # 39;,, sizeof (mine_board));      ,SetMines (mine_board,,行,上校);   ,int  count =, (ROW 安康;2),*,(COL 安康;2),背后,num;   ,int  x =, 0;   ,int  y =, 0;   ,do  {   ,ShowBoard (show_board,,行,上校);   ,printf(“请输入坐标#,“);   ,scanf (“% d  % d",,, x,, y);   ,if  (x  & lt;, 1, | |, x 祝辞,ROW 作用;2,| |,y  & lt;, 1, | |, y 祝辞,COL 作用;2),{   ,printf(“输入位置越界,请重新输入! \ n");   ,继续;   ,}   ,if  (show_board [x] [y], !=, & # 39; * & # 39;), {   ,printf(“该位置已经被排除! \ n");   ,继续;   ,}   ,if  (mine_board [x] [y],==, & # 39; 1 & # 39;), {   ,打破;   ,}   ,int  num =, GetNums (mine_board,,行,,,上校,x,, y);   ,show_board [x] [y],=, num  +, & # 39; 0 & # 39;;   ,计数,   ,系统(“cls");   ,}while  (count 祝辞,0);   ,if  (count 祝辞,0),{   ,printf(“你被炸死了! \ n");   ,ShowBoard (mine_board,,行,上校);   ,}   ,else  {   ,printf(“恭喜,你通过游戏! \ n");   ,}   }

主要。c

# include “game.h"      void 菜单()   {   ,printf (“# # # # # # # # # # # # # # # # # # # # # # # # # # # \ n");   ,printf (“# #, 1. play  2只Exit  # # \ n");   ,printf (“# # # # # # # # # # # # # # # # # # # # # # # # # # # \ n");   ,printf(“请输入#,“);   }   void  SetMines (char  [] (COL), int 行,int 坳)   {   ,int  num =, num;   ,while  (num), {   ,int  x =, rand (), %, 10, +, 1;   ,int  y =, rand (), %, 10, +, 1;   ,if (董事会[x] [y],==, & # 39; 0 & # 39;), {   ,董事会[x] [y],=, & # 39; 1 & # 39;;   ,num -;   ,}   ,}   }   int  GetNums (char  [] (COL), int 行,int ,上校,int  x,, int  y)   {   ,return 董事会[x 安康;1][y 安康;1],+,董事会[x 安康;1][y], + \   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

使用C语言编写一个扫雷游戏