-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathMineSweeperData.java
48 lines (36 loc) · 1.39 KB
/
MineSweeperData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class MineSweeperData {
public static final String blockImageURL = "resources/block.png";
public static final String flagImageURL = "resources/flag.png";
public static final String mineImageURL = "resources/mine.png";
public static String numberImageURL(int num){
if(num < 0 || num > 8)
throw new IllegalArgumentException("No such a number image!");
return "resources/" + num + ".png";
}
private int N, M;
private boolean[][] mines;
public MineSweeperData(int N, int M, int mineNumber){
if(N <= 0 || M <= 0)
throw new IllegalArgumentException("Mine sweeper size is invalid!");
if(mineNumber < 0 || mineNumber > N*M)
throw new IllegalArgumentException("Mine number is larger than the size of mine sweeper board!");
this.N = N;
this.M = M;
mines = new boolean[N][M];
for(int i = 0 ; i < N ; i ++)
for(int j = 0 ; j < M ; j ++){
mines[i][j] = false;
}
mines[0][0] = true;
}
public int N(){ return N; }
public int M(){ return M; }
public boolean isMine(int x, int y){
if(!inArea(x, y))
throw new IllegalArgumentException("Out of index in isMine function!");
return mines[x][y];
}
public boolean inArea(int x, int y){
return x >= 0 && x < N && y >= 0 && y < M;
}
}