Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5287d13b
Commit
5287d13b
authored
Oct 03, 2015
by
Mehmet Akin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplfy resetting board and mine generation.
parent
e9f27245
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
24 deletions
+16
-24
main.dart
examples/mine_digger/lib/main.dart
+16
-24
No files found.
examples/mine_digger/lib/main.dart
View file @
5287d13b
...
...
@@ -64,33 +64,25 @@ class MineDiggerState extends State<MineDigger> {
alive
=
true
;
hasWon
=
false
;
detectedCount
=
0
;
// Build the arrays.
cells
=
new
List
<
List
<
bool
>>();
uiState
=
new
List
<
List
<
CellState
>>();
for
(
int
iy
=
0
;
iy
!=
rows
;
iy
++)
{
cells
.
add
(
new
List
<
bool
>());
uiState
.
add
(
new
List
<
CellState
>());
for
(
int
ix
=
0
;
ix
!=
cols
;
ix
++)
{
cells
[
iy
].
add
(
false
);
uiState
[
iy
].
add
(
CellState
.
covered
);
}
}
// Initialize matrices.
cells
=
new
List
<
List
>.
generate
(
rows
,
(
int
row
)
{
return
new
List
<
bool
>.
filled
(
cols
,
false
);
});
uiState
=
new
List
<
List
>.
generate
(
rows
,
(
int
row
)
{
return
new
List
<
CellState
>.
filled
(
cols
,
CellState
.
covered
);
});
// Place the mines.
Random
random
=
new
Random
();
int
cellsRemaining
=
rows
*
cols
;
int
minesRemaining
=
totalMineCount
;
for
(
int
x
=
0
;
x
<
cols
;
x
+=
1
)
{
for
(
int
y
=
0
;
y
<
rows
;
y
+=
1
)
{
if
(
random
.
nextInt
(
cellsRemaining
)
<
minesRemaining
)
{
cells
[
y
][
x
]
=
true
;
minesRemaining
-=
1
;
if
(
minesRemaining
<=
0
)
return
;
}
cellsRemaining
-=
1
;
while
(
minesRemaining
>
0
)
{
int
pos
=
random
.
nextInt
(
rows
*
cols
);
int
row
=
pos
~/
rows
;
int
col
=
pos
%
cols
;
if
(!
cells
[
row
][
col
])
{
cells
[
row
][
col
]
=
true
;
minesRemaining
--;
}
}
assert
(
false
);
}
PointerEventListener
_pointerDownHandlerFor
(
int
posX
,
int
posY
)
{
...
...
@@ -106,9 +98,9 @@ class MineDiggerState extends State<MineDigger> {
Widget
buildBoard
()
{
bool
hasCoveredCell
=
false
;
List
<
Row
>
flexRows
=
<
Row
>[];
for
(
int
iy
=
0
;
iy
!=
9
;
iy
++)
{
for
(
int
iy
=
0
;
iy
<
rows
;
iy
++)
{
List
<
Widget
>
row
=
<
Widget
>[];
for
(
int
ix
=
0
;
ix
!=
9
;
ix
++)
{
for
(
int
ix
=
0
;
ix
<
cols
;
ix
++)
{
CellState
state
=
uiState
[
iy
][
ix
];
int
count
=
mineCount
(
ix
,
iy
);
if
(!
alive
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment