@@ -29,7 +29,7 @@ Game_Map make_map()// NOLINT cognitive complexity
2929 fill (pixels, Color{ 0 , 0 , 250 , 255 });// NOLINT magic number
3030 };
3131
32-
32+ const std::string location_string = fmt::format ( " {}:{} " , __FILE__, __LINE__);
3333 auto wall_draw = [colors_used]([[maybe_unused]] Vector2D_Span<Color> &pixels,
3434 [[maybe_unused]] const Game &game,
3535 [[maybe_unused]] Point map_location,
@@ -58,13 +58,18 @@ Game_Map make_map()// NOLINT cognitive complexity
5858 // static constexpr auto MyPrettyBlue = Color{10,24, 200, 255}; // for example
5959 //
6060 // Also consider naming the other colors used!
61+
62+ static constexpr auto mint_green = Color{ 64 , 128 , 64 , 255 };
63+
6164 switch ((game.clock .count () / 1000 ) % 2 ) {// NOLINT magic number
6265 case 0 :
63- fill (pixels, Color{ 64 , 128 , 64 , 255 }); // NOLINT magic number
66+ fill (pixels, mint_green);
6467 break ;
6568 case 1 :
6669 fill (pixels, Color{ 128 , 64 , 64 , 255 });// NOLINT magic number
6770 break ;
71+
72+ // When you add a new color, try to not use // NOLINT!
6873 }
6974
7075 colors_used->insert (pixels.at (Point{ 3 , 3 }));
@@ -108,18 +113,72 @@ Game_Map make_map()// NOLINT cognitive complexity
108113 map.locations .at (Point{ 8 , 6 }) = Flashing_Tile;// NOLINT magic numbers
109114 map.locations .at (Point{ 5 , 5 }) = Flashing_Tile;// NOLINT magic numbers
110115
116+ static constexpr auto test_and_set =
117+ [](Game &game, const std::string &key_to_test, const std::string &key_to_set) -> bool // NOLINT easily swappable
118+ {
119+ if (const auto &value = game.variables .find (key_to_test);
120+ value != game.variables .end () && std::get<bool >(value->second )) {
121+ game.variables [key_to_set] = true ;
122+ return true ;
123+ } else {
124+ return false ;
125+ }
126+ };
127+
111128 map.locations .at (Point{ 2 , 1 }).enter_action = [](Game &game, Point, Direction) {
112129 game.last_message = " What is a Magic Number? {2,3}" ;
130+ game.variables [" clue1" ] = true ;
113131 };
114132
115133 map.locations .at (Point{ 2 , 3 }).enter_action = [](Game &game, Point, Direction) {
116- game.last_message = " Magic Number? https://en.wikipedia.org/wiki/Magic_number_(programming) {4, 3}" ;
134+ if (test_and_set (game, " clue1" , " clue2" )) {
135+ game.last_message = " Magic Number? https://en.wikipedia.org/wiki/Magic_number_(programming) {4, 3}" ;
136+ }
117137 };
118138
119139 map.locations .at (Point{ 4 , 3 }).enter_action = [](Game &game, Point, Direction) {
120- game.last_message = " It's a hard coded constant. This is generally a 'Code Smell'" ;
140+ if (test_and_set (game, " clue2" , " clue3" )) {
141+ game.last_message = " It's a hard coded constant. This is generally a 'Code Smell' {3, 5}" ;
142+ }
143+ };
144+
145+ map.locations .at (Point{ 3 , 5 }).enter_action = [](Game &game, Point, Direction) {// NOLINT magic number
146+ if (test_and_set (game, " clue3" , " clue4" )) {
147+ game.last_message = " 'Code Smells' might indicate other problems in your code {1, 8}" ;
148+ }
149+ };
150+
151+ map.locations .at (Point{ 1 , 8 }).enter_action = [](Game &game, Point, Direction) {// NOLINT magic number
152+ if (test_and_set (game, " clue4" , " clue5" )) {
153+ game.last_message = " This code has many // NOLINT comments to prevent 'magic number' warnings {8, 1}" ;
154+ }
155+ };
156+
157+ map.locations .at (Point{ 8 , 1 }).enter_action = [](Game &game, Point, Direction) {// NOLINT magic number
158+ if (test_and_set (game, " clue5" , " clue6" )) {
159+ game.last_message = fmt::format (" Most of these are for colors and locations. Look in {}. {{8, 7}}" , __FILE__);
160+ }
161+ };
162+
163+ map.locations .at (Point{ 8 , 7 }).enter_action = [](Game &game, Point, Direction) {// NOLINT magic number
164+ if (test_and_set (game, " clue6" , " clue7" )) {
165+ game.last_message = " Named constants avoid this warning. Ex: const auto Blue = Color{0,0,255,255}; {7, 8}" ;
166+ }
121167 };
122168
169+ map.locations .at (Point{ 7 , 8 }).enter_action = [](Game &game, Point, Direction) {// NOLINT magic number
170+ if (test_and_set (game, " clue7" , " clue8" )) {
171+ game.last_message = " To access the buttom corner, you need to display *more than 2* colors {5, 6}" ;
172+ }
173+ };
174+
175+ map.locations .at (Point{ 5 , 6 }).enter_action = [=](Game &game, Point, Direction) {// NOLINT magic number
176+ if (test_and_set (game, " clue8" , " clue9" )) {
177+ game.last_message = fmt::format (" Check out {} for more info on how to add colors." , location_string);
178+ }
179+ };
180+
181+
123182 map.locations .at (special_location) = Flashing_Tile;
124183 map.locations .at (special_location).can_enter =
125184 [colors_used]([[maybe_unused]] const Game &game, Point, [[maybe_unused]] Direction direction) {
0 commit comments