Skip to content

Commit d82bcbc

Browse files
committed
first commit
0 parents  commit d82bcbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1349
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HelloGitHub

puzzlegame/image/扫雷/logo.png

12.2 KB
Loading
1.33 KB
Loading

puzzlegame/image/扫雷/中等.jpg

1.33 KB
Loading

puzzlegame/image/扫雷/困难.jpg

1.39 KB
Loading

puzzlegame/image/扫雷/数字/1.jpg

846 Bytes
Loading

puzzlegame/image/扫雷/数字/2.jpg

994 Bytes
Loading

puzzlegame/image/扫雷/数字/3.jpg

977 Bytes
Loading

puzzlegame/image/扫雷/数字/4.jpg

939 Bytes
Loading

puzzlegame/image/扫雷/数字/5.jpg

989 Bytes
Loading

puzzlegame/image/扫雷/数字/6.jpg

981 Bytes
Loading

puzzlegame/image/扫雷/未点击.jpg

879 Bytes
Loading
1.13 KB
Loading
1.35 KB
Loading

puzzlegame/image/扫雷/空白区.jpg

728 Bytes
Loading

puzzlegame/image/扫雷/简单.jpg

1.37 KB
Loading

puzzlegame/image/扫雷/雷1.jpg

1.21 KB
Loading

puzzlegame/image/扫雷/雷2.jpg

1.25 KB
Loading
3.22 KB
Loading

puzzlegame/puzzlegame.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

puzzlegame/src/META-INF/MANIFEST.MF

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: TestGame.Main
3+
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package TestGame;
2+
3+
import java.util.*;
4+
5+
import java.util.Random;
6+
7+
public class Algorithm {
8+
9+
// 0: 无,1: 有雷,2: 标记雷,3: 无雷(已点开),>3: 周围雷的数量, -1: 显示所有雷, -3: 点到雷区域
10+
public static void algorithm(int[][] data, int x, int y, int m, int n) {
11+
// 如果点击的是标记的区域,直接返回
12+
if (data[x][y] == 2) return;
13+
14+
// 已点击区域标记为3
15+
data[x][y] = 3;
16+
17+
// 检查周围8个方向是否有雷
18+
int[][] directions = {{1,1}, {1,0}, {1,-1}, {0,1}, {0,-1}, {-1,1}, {-1,0}, {-1,-1}};
19+
boolean noBombsAround = true;
20+
21+
for (int[] dir : directions) {
22+
int newX = x + dir[0];
23+
int newY = y + dir[1];
24+
if (newX > 0 && newX <= m && newY > 0 && newY <= n) {
25+
if (data[newX][newY] == 1 || data[newX][newY] == 2) {
26+
noBombsAround = false;
27+
break;
28+
}
29+
}
30+
}
31+
32+
// 如果周围没有雷,则递归检查周围区域
33+
if (noBombsAround) {
34+
for (int[] dir : directions) {
35+
int newX = x + dir[0];
36+
int newY = y + dir[1];
37+
if (newX > 0 && newX <= m && newY > 0 && newY <= n && data[newX][newY] == 0) {
38+
algorithm(data, newX, newY, m, n);
39+
}
40+
}
41+
} else {
42+
// 如果周围有雷,则计算雷的数量
43+
int bombCount = 0;
44+
for (int[] dir : directions) {
45+
int newX = x + dir[0];
46+
int newY = y + dir[1];
47+
if (newX > 0 && newX <= m && newY > 0 && newY <= n) {
48+
if (data[newX][newY] == 1 || data[newX][newY] == 2) {
49+
bombCount++;
50+
}
51+
}
52+
}
53+
data[x][y] = 3 + bombCount; // 将雷的数量存储在当前单元格
54+
}
55+
}
56+
57+
58+
59+
public static void initBoom(int[][] data, int x, int y, int m, int n, int num) {
60+
// 先标记点击区域及其周围区域
61+
int[][] directions = {{0,0}, {1,1}, {1,0}, {1,-1}, {0,1}, {0,-1}, {-1,1}, {-1,0}, {-1,-1}};
62+
for (int[] dir : directions) {
63+
int newX = x + dir[0];
64+
int newY = y + dir[1];
65+
if (newX >= 0 && newX <= m && newY >= 0 && newY <= n) {
66+
data[newX][newY] = 12; // 临时标记
67+
}
68+
}
69+
70+
// 创建一个包含所有可能放置雷的位置的列表
71+
List<int[]> possiblePositions = new ArrayList<>();
72+
for (int i = 0; i <= m; i++) {
73+
for (int j = 0; j <= n; j++) {
74+
if (data[i][j] == 0) {
75+
possiblePositions.add(new int[]{i, j});
76+
}
77+
}
78+
}
79+
80+
// 随机打乱列表
81+
Collections.shuffle(possiblePositions);
82+
83+
// 从打乱的列表中选择前num个位置放置雷
84+
for (int i = 0; i < num; i++) {
85+
int[] pos = possiblePositions.get(i);
86+
data[pos[0]][pos[1]] = 1;
87+
}
88+
89+
// 取消临时标记
90+
for (int[] dir : directions) {
91+
int newX = x + dir[0];
92+
int newY = y + dir[1];
93+
if (newX >= 0 && newX <= m && newY >= 0 && newY <= n) {
94+
data[newX][newY] = 0;
95+
}
96+
}
97+
}
98+
}
99+

0 commit comments

Comments
 (0)