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
32558478
Commit
32558478
authored
Sep 30, 2015
by
mdakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix alignment of mine counts, simplfy code a bit.
parent
1203b08b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
31 deletions
+26
-31
main.dart
examples/mine_digger/lib/main.dart
+26
-31
No files found.
examples/mine_digger/lib/main.dart
View file @
32558478
...
...
@@ -19,18 +19,21 @@ import 'package:sky/src/fn3.dart';
// CoveredMineNode and ExposedMineNode, none of them holding state.
// Colors for each mine count (0-8):
const
List
<
TextStyle
>
textStyles
=
const
<
TextStyle
>[
const
TextStyle
(
color:
const
Color
(
0xFF555555
),
fontWeight:
bold
),
const
TextStyle
(
color:
const
Color
(
0xFF0094FF
),
fontWeight:
bold
),
// blue
const
TextStyle
(
color:
const
Color
(
0xFF13A023
),
fontWeight:
bold
),
// green
const
TextStyle
(
color:
const
Color
(
0xFFDA1414
),
fontWeight:
bold
),
// red
const
TextStyle
(
color:
const
Color
(
0xFF1E2347
),
fontWeight:
bold
),
// black
const
TextStyle
(
color:
const
Color
(
0xFF7F0037
),
fontWeight:
bold
),
// dark red
const
TextStyle
(
color:
const
Color
(
0xFF000000
),
fontWeight:
bold
),
const
TextStyle
(
color:
const
Color
(
0xFF000000
),
fontWeight:
bold
),
const
TextStyle
(
color:
const
Color
(
0xFF000000
),
fontWeight:
bold
),
const
List
<
Color
>
textColors
=
const
<
Color
>[
const
Color
(
0xFF555555
),
const
Color
(
0xFF0094FF
),
// blue
const
Color
(
0xFF13A023
),
// green
const
Color
(
0xFFDA1414
),
// red
const
Color
(
0xFF1E2347
),
// black
const
Color
(
0xFF7F0037
),
// dark red
const
Color
(
0xFF000000
),
const
Color
(
0xFF000000
),
const
Color
(
0xFF000000
),
];
final
List
<
TextStyle
>
textStyles
=
textColors
.
map
((
c
)
=>
new
TextStyle
(
color:
c
,
fontWeight:
bold
,
textAlign:
TextAlign
.
center
)).
toList
();
enum
CellState
{
covered
,
exploded
,
cleared
,
flagged
,
shown
}
class
MineDigger
extends
StatefulComponent
{
...
...
@@ -235,11 +238,8 @@ class MineDiggerState extends State<MineDigger> {
// Recursively uncovers cells whose totalMineCount is zero.
void
cull
(
int
x
,
int
y
)
{
if
((
x
<
0
)
||
(
x
>
rows
-
1
))
return
;
if
((
y
<
0
)
||
(
y
>
cols
-
1
))
if
(!
inBoard
(
x
,
y
))
return
;
if
(
uiState
[
y
][
x
]
==
CellState
.
cleared
)
return
;
uiState
[
y
][
x
]
=
CellState
.
cleared
;
...
...
@@ -259,25 +259,21 @@ class MineDiggerState extends State<MineDigger> {
int
mineCount
(
int
x
,
int
y
)
{
int
count
=
0
;
int
my
=
cols
-
1
;
int
mx
=
rows
-
1
;
count
+=
x
>
0
?
bombs
(
x
-
1
,
y
)
:
0
;
count
+=
x
<
mx
?
bombs
(
x
+
1
,
y
)
:
0
;
count
+=
y
>
0
?
bombs
(
x
,
y
-
1
)
:
0
;
count
+=
y
<
my
?
bombs
(
x
,
y
+
1
)
:
0
;
count
+=
(
x
>
0
)
&&
(
y
>
0
)
?
bombs
(
x
-
1
,
y
-
1
)
:
0
;
count
+=
(
x
<
mx
)
&&
(
y
<
my
)
?
bombs
(
x
+
1
,
y
+
1
)
:
0
;
count
+=
(
x
<
mx
)
&&
(
y
>
0
)
?
bombs
(
x
+
1
,
y
-
1
)
:
0
;
count
+=
(
x
>
0
)
&&
(
y
<
my
)
?
bombs
(
x
-
1
,
y
+
1
)
:
0
;
count
+=
bombs
(
x
-
1
,
y
);
count
+=
bombs
(
x
+
1
,
y
);
count
+=
bombs
(
x
,
y
-
1
);
count
+=
bombs
(
x
,
y
+
1
);
count
+=
bombs
(
x
-
1
,
y
-
1
);
count
+=
bombs
(
x
+
1
,
y
+
1
);
count
+=
bombs
(
x
+
1
,
y
-
1
);
count
+=
bombs
(
x
-
1
,
y
+
1
);
return
count
;
}
int
bombs
(
int
x
,
int
y
)
{
return
cells
[
y
][
x
]
?
1
:
0
;
}
int
bombs
(
int
x
,
int
y
)
=>
inBoard
(
x
,
y
)
&&
cells
[
y
][
x
]
?
1
:
0
;
bool
inBoard
(
int
x
,
int
y
)
=>
(
x
>
0
&&
x
<
(
cols
-
1
)
&&
y
>
0
&&
y
<
(
rows
-
1
));
}
Widget
buildCell
(
Widget
child
)
{
...
...
@@ -343,7 +339,6 @@ class ExposedMineNode extends StatelessComponent {
}
return
buildCell
(
buildInnerCell
(
text
));
}
}
void
main
(
)
{
...
...
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