@@ -93,7 +93,7 @@ struct GameBoard {
93
93
}
94
94
95
95
bool & hints ( const Point & p ) {
96
- return hints_[ p.x + p.y * width] ;
96
+ return hints_. at ( p.x + p.y * width ) ;
97
97
}
98
98
99
99
GameBoard () {
@@ -114,7 +114,7 @@ struct GameBoard {
114
114
// / Togle cross (5 LEDs)
115
115
void press ( const Point &p ) {
116
116
++move_count;
117
- hints_ [ p.x + p.y * width] ^= true ;
117
+ hints_. at ( p.x + p.y * width ) ^= true ;
118
118
toggle ( p );
119
119
toggle ( p - Point { 1 , 0 } );
120
120
toggle ( p - Point { 0 , 1 } );
@@ -137,11 +137,18 @@ struct GameBoard {
137
137
}
138
138
};
139
139
140
+ // -----------------------------------------------------------------------------//
141
+ struct Bools {
142
+ bool *state;
143
+ bool * hint;
144
+ bool * show_hints;
145
+ };
146
+
140
147
// -----------------------------------------------------------------------------//
141
148
class LEDBase : public ComponentBase {
142
149
public:
143
- LEDBase ( bool *state, bool *hint, bool * show_hints , std::function<void () > on_click ) :
144
- state_ ( state ), hint_ ( hint ), show_hints_ ( show_hints ), hovered_ ( false ), on_change ( std::move ( on_click ) ) {}
150
+ LEDBase ( const Bools& b , std::function<void () > on_click ) :
151
+ state_ ( b. state ), hint_ ( b. hint ), show_hints_ ( b. show_hints ), hovered_ ( false ), on_change ( std::move ( on_click ) ) {}
145
152
146
153
private:
147
154
// Component implementation.
@@ -187,7 +194,7 @@ class LEDBase : public ComponentBase {
187
194
auto c = [&] ( std::size_t i ) {
188
195
auto v = uint8_t ( r * pattern_on.at ( i ) + ( 1.0 - r ) * pattern_off.at ( i ) );
189
196
v = uint8_t ( v * std::numeric_limits<uint8_t >::max () / 100 ); // NOLINT magic numbers
190
- if ( show_hints_ && *show_hints_ && hint_ && *hint_ ) {
197
+ if ( show_hints_ != nullptr && *show_hints_ && hint_ != nullptr && *hint_ ) {
191
198
return Color ( v, v * uint8_t ( hovered_ ), 0 );
192
199
}
193
200
return Color ( v * uint8_t ( !hovered_ ), v, v * uint8_t ( !hovered_ ) );
@@ -274,8 +281,9 @@ class LEDBase : public ComponentBase {
274
281
};
275
282
276
283
// -----------------------------------------------------------------------------//
277
- Component LED ( bool *b, bool * hint, bool * show_hints, const std::function<void () >& on_click ) {
278
- return Make<LEDBase> ( b, hint, show_hints, on_click );
284
+ // Component LED ( bool *b, bool* hint, bool* show_hints, const std::function<void() >& on_click ) {
285
+ Component LED ( const Bools& bools, const std::function<void () >& on_click ) {
286
+ return Make<LEDBase> ( bools, on_click );
279
287
}
280
288
281
289
// -----------------------------------------------------------------------------//
@@ -320,7 +328,8 @@ void game ( const auto& header, const auto& footer, uint32_t random_seed ) {
320
328
std::vector<Component> leds;
321
329
leds.reserve ( gb.width * gb.height );
322
330
gb.visit ( [&] ( const auto & p, auto & gbo ) {
323
- leds.push_back ( LED ( &gbo[p], &gbo.hints ( p ), &show_hints, [ =, &gbo] {
331
+ const Bools b{&gbo[p], &gbo.hints ( p ), &show_hints};
332
+ leds.push_back ( LED ( b, [ =, &gbo] {
324
333
if ( !gbo.solved () ) {
325
334
gbo.press ( p );
326
335
}
@@ -368,7 +377,7 @@ void game ( const auto& header, const auto& footer, uint32_t random_seed ) {
368
377
back_button->Render (),
369
378
filler (),
370
379
hints_button->Render (), reset_button->Render (), new_button->Render (),
371
- filler (), hbox () | size ( WIDTH, EQUAL, 10 ) } ),
380
+ filler (), hbox () | size ( WIDTH, EQUAL, 10 ) } ),// NOLINT magic numbers
372
381
footer,
373
382
} );
374
383
};
0 commit comments