FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaSweeper/src/sweeper/Bomb.java at master · pandim/JavaSweeper · GitHub
pandim
/
JavaSweeper
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaSweeper
/
src
/
sweeper
/
Bomb.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (39 loc) · 1.13 KB
Breadcrumbs
JavaSweeper
/
src
/
sweeper
/
Bomb.java
Copy path
File metadata and controls
48 lines (39 loc) · 1.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
sweeper
;
class
Bomb
{
private
Matrix
bombMap
;
private
int
totalBombs
;
Bomb
(
int
totalBombs
) {
this
.
totalBombs
=
totalBombs
;
fixBombCount
();
}
void
start
() {
bombMap
=
new
Matrix
(
Box
.
ZERO
);
for
(
int
j
=
0
;
j
<
totalBombs
;
j
++)
placeBomb
();
}
Box
get
(
Coord
coord
) {
return
bombMap
.
get
(
coord
);
}
int
getTotalBombs
(){
return
totalBombs
;
}
private
void
fixBombCount
(){
int
maxBombs
=
Ranges
.
getSize
().
x
*
Ranges
.
getSize
().
y
/
2
;
if
(
totalBombs
>
maxBombs
)
totalBombs
=
maxBombs
;
}
private
void
placeBomb
() {
while
(
true
) {
Coord
coord
=
Ranges
.
getRandomCoord
();
if
(
Box
.
BOMB
==
bombMap
.
get
(
coord
))
continue
;
bombMap
.
set
(
coord
,
Box
.
BOMB
);
incNumbersAroundBomb
(
coord
);
break
;
}
}
private
void
incNumbersAroundBomb
(
Coord
coord
) {
for
(
Coord
around
:
Ranges
.
getCoordsAround
(
coord
))
if
(
Box
.
BOMB
!=
bombMap
.
get
(
around
))
bombMap
.
set
(
around
,
bombMap
.
get
(
around
).
nextNumberBox
());
}
}
Back
|
FazBrowse Home
|
New Git URL