Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 670f27a

Browse files
Add files via upload
1 parent f84ce2b commit 670f27a

File tree

9 files changed

+171
-0
lines changed

9 files changed

+171
-0
lines changed

‎扫雷1.0/DisplayBoard.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for (int i = 1; i <= row; i++)
13+
{
14+
printf("%d ", i);// ́òÓ¡ÁÐ
15+
for (int j = 1; j <= col; j++)
16+
{
17+
printf("%c ", board[i][j]);
18+
}
19+
printf("\n");
20+
}
21+
printf("x");
22+
printf("\n--------------------\n");
23+
}

‎扫雷1.0/FindMine.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "game.h"
2+
void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
3+
{
4+
int x = 0;
5+
int y = 0;
6+
int win = 0;
7+
while (win<row*col-COUNT)
8+
{
9+
10+
//DisplayBoard(mine, ROW, COL);//作弊模式:)
11+
printf("输入排查雷的坐标 x y :>");
12+
scanf("%d %d", &x, &y);
13+
if (x >= 1 && x <= row && y >= 1 && y <= col)
14+
{
15+
if (mine[x][y] == '1')
16+
{
17+
printf("这是雷,很遗憾游戏结束\n");
18+
DisplayBoard(mine, ROW, COL);
19+
Sleep(3000);
20+
system("cls");
21+
break;
22+
}
23+
else
24+
{
25+
win++;
26+
system("cls");
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+
else
35+
{
36+
printf("输入有误,重新输入\n");
37+
}
38+
39+
}
40+
if (win== row * col - COUNT)
41+
printf("赢了\n");
42+
}

‎扫雷1.0/GetMineCount.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "game.h"
2+
int GetMineCount(char mine[ROWS][COLS],int x,int y)
3+
{
4+
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';
5+
}

‎扫雷1.0/InitBoard.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "game.h"
2+
//3õÊ1⁄4» ×ばつÇø
3+
void InitBoard(char board[ROWS][COLS], int row, int col, char set)
4+
{
5+
for (int i = 0; i < row; i++)
6+
{
7+
for (int j = 0; j < col; j++)
8+
{
9+
board[i][j] = set;
10+
}
11+
}
12+
}

‎扫雷1.0/SetMine.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "game.h"
2+
void SetMine(char board[ROWS][COLS], int row, int col)
3+
{
4+
int count = 10;
5+
while (count)
6+
{
7+
int x = rand() % row + 1;//x:1~9
8+
int y = rand() % col + 1;//y:1~9
9+
if (board[x][y] != '1')
10+
{
11+
board[x][y] = '1';
12+
count--;
13+
}
14+
}
15+
16+
}

‎扫雷1.0/game.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "game.h"
2+
void game()
3+
{
4+
char mine[ROWS][COLS] = { 0 };//定义布雷数组
5+
char show[ROWS][COLS] = { 0 };//定义显示玩家排雷的状态的数组
6+
InitBoard(mine, ROWS, COLS, '0');//初始化布雷数组
7+
InitBoard(show, ROWS, COLS, '?');//初始化显示玩家排雷的状态的数组
8+
SetMine(mine, ROW,COL);//布雷
9+
DisplayBoard(show, ROW, COL);//打印显示玩家排雷的状态的数组
10+
FindMine(mine,show,ROW,COL);//玩家找雷
11+
}

‎扫雷1.0/game.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
#define _CRT_SECURE_NO_WARNINGS
3+
#define ROW 9
4+
#define COL 9
5+
#define ROWS ROW+2
6+
#define COLS COL+2
7+
#define COUNT 10
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <windows.h>
11+
#include <time.h>
12+
void menu();
13+
void game();
14+
void InitBoard(char board[ROWS][COLS], int row, int col, char set);
15+
void SetMine(char board[ROWS][COLS], int row, int col);
16+
void DisplayBoard(char board[ROWS][COLS], int row, int col);
17+
void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col);
18+
int GetMineCount(char mine[ROWS][COLS], int x, int y);

‎扫雷1.0/main.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#include "game.h"
3+
int main()
4+
{
5+
int tmp = 0;
6+
srand((unsigned int)time(NULL));
7+
do
8+
{
9+
menu();//调用菜单函数
10+
scanf("%d", &tmp);
11+
switch (tmp)
12+
{
13+
case 2:
14+
break;
15+
default:
16+
{
17+
printf("输入错误,重新选择!\n");
18+
Sleep(1000);
19+
system("cls");
20+
break;
21+
}
22+
case 1:
23+
{
24+
system("cls");
25+
game();
26+
break;
27+
}
28+
29+
}
30+
31+
}
32+
while (tmp != 2);
33+
return 0;
34+
}
35+

‎扫雷1.0/menu.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "game.h"
2+
void menu()//Ö÷2Ëμ\o ̄Êý
3+
{
4+
printf("**********************************************\n");
5+
printf("*******************1.PLAY********************\n");
6+
printf("*******************2.EXIT*********************\n");
7+
printf("**********************************************\n");
8+
printf("ÇëÑ¡Ôñ£o\n");
9+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /