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 797ea2f

Browse files
Chapter 07 section 05-06 codes updated.
1 parent 13d524d commit 797ea2f

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

‎07-Mine-Sweeper/05-Knuth-Shuffle/01-Knuth-Shuffle-1/src/KnuthShuffle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private void reset(int[] arr){
4949
private void shuffle(int[] arr){
5050

5151
for(int i = 0 ; i < n ; i ++){
52+
// 从 [i, n) 区间里随机选择元素
5253
int x = (int)(Math.random() * (n-i)) + i;
5354
swap(arr, i, x);
5455
}

‎07-Mine-Sweeper/06-Interactions-in-Mine-Sweeper/src/AlgoVisualizer.java

Lines changed: 6 additions & 9 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

@@ -33,13 +32,11 @@ public void run(){
3332
}
3433

3534
private void setData(boolean isLeftClicked, int x, int y){
36-
if(isLeftClicked){
37-
if(data.inArea(x, y))
35+
if(data.inArea(x, y)){
36+
if(isLeftClicked)
3837
data.open[x][y] = true;
39-
}
40-
else{
41-
if(data.inArea(x, y))
42-
data.flags[x][y] = true;
38+
else
39+
data.flags[x][y] = !data.flags[x][y];
4340
}
4441

4542
frame.render(data);
@@ -80,8 +77,8 @@ else if(SwingUtilities.isRightMouseButton(event))
8077
public static void main(String[] args) {
8178

8279
int N = 20;
83-
int M = 30;
84-
int mineNumber = 20;
80+
int M = 20;
81+
int mineNumber = 50;
8582

8683
AlgoVisualizer vis = new AlgoVisualizer(N, M, mineNumber);
8784
}

‎07-Mine-Sweeper/06-Interactions-in-Mine-Sweeper/src/MineSweeperData.java

Lines changed: 1 addition & 1 deletion
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
}

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

187 KB
Binary file not shown.

0 commit comments

Comments
(0)

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