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 6be898b

Browse files
Chapter 07 completed.
1 parent 797ea2f commit 6be898b

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

‎07-Mine-Sweeper/07-Floodfill-in-Mine-Sweeper/src/AlgoVisualizer.java‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class AlgoVisualizer {
99

1010
private MineSweeperData data;
1111
private AlgoFrame frame;
12-
private static final int d[][] = {{-1,0},{0,1},{1,0},{0,-1}};
1312

1413
public AlgoVisualizer(int N, int M, int mineNumber){
1514

@@ -28,23 +27,22 @@ public AlgoVisualizer(int N, int M, int mineNumber){
2827

2928
public void run(){
3029

31-
this.setData(false, -1, -1);
30+
setData(false, -1, -1);
3231

3332
}
3433

3534
private void setData(boolean isLeftClicked, int x, int y){
36-
if(isLeftClicked){
37-
if(data.inArea(x, y))
35+
36+
if(data.inArea(x, y)){
37+
if(isLeftClicked){
3838
if(data.isMine(x, y)){
3939
// Game Over
4040
data.open[x][y] = true;
4141
}
4242
else
4343
data.open(x, y);
44-
}
45-
else{
46-
if(data.inArea(x, y))
47-
// data.flags[x][y] = true;
44+
}
45+
else
4846
data.flags[x][y] = !data.flags[x][y];
4947
}
5048

@@ -86,8 +84,8 @@ else if(SwingUtilities.isRightMouseButton(event))
8684
public static void main(String[] args) {
8785

8886
int N = 20;
89-
int M = 30;
90-
int mineNumber = 20;
87+
int M = 20;
88+
int mineNumber = 50;
9189

9290
AlgoVisualizer vis = new AlgoVisualizer(N, M, mineNumber);
9391
}

‎07-Mine-Sweeper/07-Floodfill-in-Mine-Sweeper/src/MineSweeperData.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class MineSweeperData {
44
public static final String flagImageURL = "resources/flag.png";
55
public static final String mineImageURL = "resources/mine.png";
66
public static String numberImageURL(int num){
7-
if(num < 0 || num >= 8)
7+
if(num < 0 || num > 8)
88
throw new IllegalArgumentException("No such a number image!");
99
return "resources/" + num + ".png";
1010
}
@@ -116,11 +116,14 @@ public void open(int x, int y){
116116
throw new IllegalArgumentException("Cannot open an mine block in open function.");
117117

118118
open[x][y] = true;
119-
if(getNumber(x, y) == 0){
120-
for(int i = x-1 ; i <= x + 1 ; i ++)
121-
for(int j = y-1 ; j <= y+1 ;j ++)
122-
if(inArea(i, j) && !open[i][j] && !isMine(i, j))
123-
open(i, j);
124-
}
119+
120+
if(numbers[x][y] > 0)
121+
return;
122+
123+
for(int i = x - 1 ; i <= x + 1 ; i ++)
124+
for(int j = y - 1 ; j <= y + 1 ;j ++)
125+
if(inArea(i, j) && !open[i][j] && !mines[i][j])
126+
open(i, j);
127+
125128
}
126129
}

‎07-Mine-Sweeper/Chapter-07.key‎

3.12 MB
Binary file not shown.

0 commit comments

Comments
(0)

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