We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f84ce2b commit 670f27aCopy full SHA for 670f27a
扫雷1.0/DisplayBoard.c
@@ -0,0 +1,23 @@
1
+#include "game.h"
2
+void DisplayBoard(char board[ROWS][COLS],int row,int col)
3
+{
4
+ printf("-------99É ×ばつ-------\n");
5
+ printf("0 ");
6
+ for (int i = 1; i <= row; i++)
7
+ {
8
+ printf("%d ", i);// ́òÓ¡ÐÐ
9
+ }
10
+ printf("y");
11
+ printf("\n");
12
13
14
+ printf("%d ", i);// ́òÓ¡ÁÐ
15
+ for (int j = 1; j <= col; j++)
16
17
+ printf("%c ", board[i][j]);
18
19
20
21
+ printf("x");
22
+ printf("\n--------------------\n");
23
+}
扫雷1.0/FindMine.c
@@ -0,0 +1,42 @@
+void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
+ int x = 0;
+ int y = 0;
+ int win = 0;
+ while (win<row*col-COUNT)
+
+ //DisplayBoard(mine, ROW, COL);//作弊模式:)
+ printf("输入排查雷的坐标 x y :>");
+ scanf("%d %d", &x, &y);
+ if (x >= 1 && x <= row && y >= 1 && y <= col)
+ if (mine[x][y] == '1')
+ printf("这是雷,很遗憾游戏结束\n");
+ DisplayBoard(mine, ROW, COL);
+ Sleep(3000);
+ system("cls");
+ break;
+ else
24
25
+ win++;
26
27
+ int sum = GetMineCount(mine, x, y);//t统计去心九宫格雷的个数
28
+ show[x][y] = sum + '0';
29
+ DisplayBoard(show, ROW, COL);
30
+ printf("\n还要排查%d个位置", row * col - COUNT);
31
32
33
34
35
36
+ printf("输入有误,重新输入\n");
37
38
39
40
+ if (win== row * col - COUNT)
41
+ printf("赢了\n");
42
扫雷1.0/GetMineCount.c
@@ -0,0 +1,5 @@
+int GetMineCount(char mine[ROWS][COLS],int x,int y)
+ return mine[x][y + 1] + mine[x][y - 1] + mine[x - 1][y] + mine[x + 1][y] + mine[x + 1][y + 1] + mine[x - 1][y - 1] + mine[x - 1][y + 1] + mine[x + 1][y - 1] - 8 * '0';
扫雷1.0/InitBoard.c
@@ -0,0 +1,12 @@
+//3õÊ1⁄4» ×ばつÇø
+void InitBoard(char board[ROWS][COLS], int row, int col, char set)
+ for (int i = 0; i < row; i++)
+ for (int j = 0; j < col; j++)
+ board[i][j] = set;
扫雷1.0/SetMine.c
@@ -0,0 +1,16 @@
+void SetMine(char board[ROWS][COLS], int row, int col)
+ int count = 10;
+ while (count)
+ int x = rand() % row + 1;//x:1~9
+ int y = rand() % col + 1;//y:1~9
+ if (board[x][y] != '1')
+ board[x][y] = '1';
+ count--;
扫雷1.0/game.c
@@ -0,0 +1,11 @@
+void game()
+ char mine[ROWS][COLS] = { 0 };//定义布雷数组
+ char show[ROWS][COLS] = { 0 };//定义显示玩家排雷的状态的数组
+ InitBoard(mine, ROWS, COLS, '0');//初始化布雷数组
+ InitBoard(show, ROWS, COLS, '?');//初始化显示玩家排雷的状态的数组
+ SetMine(mine, ROW,COL);//布雷
+ DisplayBoard(show, ROW, COL);//打印显示玩家排雷的状态的数组
+ FindMine(mine,show,ROW,COL);//玩家找雷
扫雷1.0/game.h
@@ -0,0 +1,18 @@
+#pragma once
+#define _CRT_SECURE_NO_WARNINGS
+#define ROW 9
+#define COL 9
+#define ROWS ROW+2
+#define COLS COL+2
+#define COUNT 10
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <time.h>
+void menu();
+void game();
+void InitBoard(char board[ROWS][COLS], int row, int col, char set);
+void SetMine(char board[ROWS][COLS], int row, int col);
+void DisplayBoard(char board[ROWS][COLS], int row, int col);
+void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col);
+int GetMineCount(char mine[ROWS][COLS], int x, int y);
扫雷1.0/main.c
@@ -0,0 +1,35 @@
+int main()
+ int tmp = 0;
+ srand((unsigned int)time(NULL));
+ do
+ menu();//调用菜单函数
+ scanf("%d", &tmp);
+ switch (tmp)
+ case 2:
+ default:
+ printf("输入错误,重新选择!\n");
+ Sleep(1000);
+ case 1:
+ game();
+ while (tmp != 2);
+ return 0;
扫雷1.0/menu.c
@@ -0,0 +1,9 @@
+void menu()//Ö÷2Ëμ\o ̄Êý
+ printf("**********************************************\n");
+ printf("*******************1.PLAY********************\n");
+ printf("*******************2.EXIT*********************\n");
+ printf("ÇëÑ¡Ôñ£o\n");
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments