Skip to content

Commit cee225d

Browse files
LightsRound.v.0.1.3
1 parent c686af7 commit cee225d

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/main.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct GameBoard {
9393
}
9494

9595
bool& hints ( const Point& p ) {
96-
return hints_[p.x + p.y * width];
96+
return hints_.at ( p.x + p.y * width );
9797
}
9898

9999
GameBoard() {
@@ -114,7 +114,7 @@ struct GameBoard {
114114
/// Togle cross (5 LEDs)
115115
void press ( const Point &p ) {
116116
++move_count;
117-
hints_ [p.x + p.y * width] ^= true;
117+
hints_.at ( p.x + p.y * width ) ^= true;
118118
toggle ( p );
119119
toggle ( p - Point{ 1, 0 } );
120120
toggle ( p - Point{ 0, 1 } );
@@ -137,11 +137,18 @@ struct GameBoard {
137137
}
138138
};
139139

140+
//-----------------------------------------------------------------------------//
141+
struct Bools {
142+
bool *state;
143+
bool* hint;
144+
bool* show_hints;
145+
};
146+
140147
//-----------------------------------------------------------------------------//
141148
class LEDBase : public ComponentBase {
142149
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 ) ) {}
145152

146153
private:
147154
// Component implementation.
@@ -187,7 +194,7 @@ class LEDBase : public ComponentBase {
187194
auto c = [&] ( std::size_t i ) {
188195
auto v = uint8_t ( r * pattern_on.at ( i ) + ( 1.0 - r ) * pattern_off.at ( i ) );
189196
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_ ) {
191198
return Color ( v, v * uint8_t ( hovered_ ), 0 );
192199
}
193200
return Color ( v * uint8_t ( !hovered_ ), v, v * uint8_t ( !hovered_ ) );
@@ -274,8 +281,9 @@ class LEDBase : public ComponentBase {
274281
};
275282

276283
//-----------------------------------------------------------------------------//
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 );
279287
}
280288

281289
//-----------------------------------------------------------------------------//
@@ -320,7 +328,8 @@ void game ( const auto& header, const auto& footer, uint32_t random_seed ) {
320328
std::vector<Component> leds;
321329
leds.reserve ( gb.width * gb.height );
322330
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] {
324333
if ( !gbo.solved() ) {
325334
gbo.press ( p );
326335
}
@@ -368,7 +377,7 @@ void game ( const auto& header, const auto& footer, uint32_t random_seed ) {
368377
back_button->Render(),
369378
filler(),
370379
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
372381
footer,
373382
} );
374383
};

0 commit comments

Comments
 (0)