33#include " game_components.hpp"
44
55
6- namespace lefticus ::my_awesome_game::game_hacking ::lesson_00 {
6+ namespace lefticus ::awesome_game::hacking ::lesson_00 {
77Game_Map make_map ()// NOLINT cognitive complexity
88{
99 Game_Map map{ Size{ 10 , 10 } };// NOLINT magic numbers
1010
1111
1212 auto empty_draw =
1313 [](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location) {
14- fill (pixels, Color{ 5 , 5 , 25 , 255 });// NOLINT magic number
14+ // just a grey
15+ fill (pixels, Color{ 25 , 25 , 25 , 255 });// NOLINT magic number
1516 };
1617
1718 auto cannot_enter = [](const Game &, Point, Direction) -> bool { return false ; };
1819
19- auto water = [](
20- Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location) {
21- fill (pixels, Color{ 0 , 0 , 250 , 255 });// NOLINT magic number
22- };
20+ auto water_draw =
21+ []( Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location) {
22+ fill (pixels, Color{ 0 , 0 , 250 , 255 });// NOLINT magic number
23+ };
2324
2425
2526 auto wall_draw = []([[maybe_unused]] Vector2D_Span<Color> &pixels,
2627 [[maybe_unused]] const Game &game,
2728 [[maybe_unused]] Point map_location) {
2829 static constexpr auto wall_color = Color{ 100 , 100 , 100 , 128 };
2930
30-
31+ // We fill in the wall with a color, the color alternates by the second
32+ // game clock is milliseconds (1000 per second)
33+ // divide by 1000 to get the current second, the % 2
34+ // gives you the remainder of current second divided by 2.
35+ // Result is that even numbered seconds have the first color
36+ // and odd numbered seconds have the second color
3137 switch ((game.clock .count () / 1000 ) % 2 ) {// NOLINT magic number
3238 case 0 :
3339 fill (pixels, Color{ 64 , 128 , 64 , 255 });// NOLINT magic number
@@ -38,6 +44,8 @@ Game_Map make_map()// NOLINT cognitive complexity
3844 }
3945
4046
47+ // Fill each of the 4 walls with the wall color if the wall is closed.
48+ // if the wall is open (can_enter_from) that direction, the do not draw the wall
4149 if (!game.maps .at (game.current_map ).can_enter_from (game, map_location, Direction::East)) {
4250 fill_line (pixels,
4351 Point{ pixels.size ().width - 1 , 0 },
@@ -61,18 +69,19 @@ Game_Map make_map()// NOLINT cognitive complexity
6169 }
6270 };
6371
64- for (std:: size_t cur_x = 0 ; cur_x < map. locations . size (). width ; ++cur_x) {
65- for (std:: size_t cur_y = 0 ; cur_y < map. locations . size (). height ; ++cur_y) {
66- map. locations . at (Point{ cur_x, cur_y }). draw = empty_draw;
67- }
68- }
72+ // be default everything is an empty, passable location
73+ fill (map. locations , Location{ {}, {}, empty_draw, {} });
74+
75+ // the entire border of the map is surrounded by water
76+ fill_border (map. locations , Location{ {}, {}, water_draw, cannot_enter });
6977
70- fill_border (map.locations , Location{ {}, {}, water, cannot_enter });
7178
7279 const auto Flashing_Tile = Location{ {}, {}, wall_draw, cannot_enter };
7380
7481 constexpr static auto special_location = Point{ 8 , 8 };
7582
83+ // Fill in the map locations with flashing tiles and hints
84+
7685 map.locations .at (Point{ 3 , 4 }) = Flashing_Tile;
7786 map.locations .at (Point{ 2 , 5 }) = Flashing_Tile;// NOLINT magic numbers
7887 map.locations .at (Point{ 1 , 2 }) = Flashing_Tile;
@@ -92,13 +101,15 @@ Game_Map make_map()// NOLINT cognitive complexity
92101 map.locations .at (Point{ 8 , 7 }).enter_action // NOLINT
93102 = [](Game &game, Point, Direction) { game.last_message = " You need to remove the wall" ; };
94103 map.locations .at (Point{ 7 , 8 }).enter_action // NOLINT
95- = [](Game &game, Point, Direction) { game.last_message = " Look for 'special_location' in the source code" ; };
104+ = [](Game &game, Point, Direction) {
105+ game.last_message = fmt::format (" Look for 'special_location' ({}:{})" , __FILE__, __LINE__);
106+ };
96107
97108 map.locations .at (special_location) = Flashing_Tile;
98109 map.locations .at (special_location).can_enter = [](const Game &, Point, [[maybe_unused]] Direction direction) {
99110 // || means "or"
100111 // this means you can currently enter the code from either
101- // the South or the East...
112+ // the South || (or) the East...
102113 // but you need to be able to enter from the North or the West!
103114 //
104115 // North
@@ -111,8 +122,6 @@ Game_Map make_map()// NOLINT cognitive complexity
111122 return direction == Direction::South || direction == Direction::East;
112123 };
113124
114- map.locations .at (special_location).exit_action = [](Game &game, Point, Direction) { game.last_message = " " ; };
115-
116125 map.locations .at (special_location).enter_action = [](Game &game, Point, Direction) {
117126 game.last_message = " You found the secret room! Now change the call to `play_game` to start lesson 01" ;
118127 Menu menu;
@@ -138,7 +147,11 @@ Game make_lesson()
138147 retval.display_variables .emplace_back (" Task" );
139148
140149 Character player;
150+
151+ // player's starting map location is {1,1}
141152 player.map_location = { 1 , 1 };
153+
154+ // Draw a circle-like thing for the player
142155 player.draw =
143156 [](Vector2D_Span<Color> &pixels, [[maybe_unused]] const Game &game, [[maybe_unused]] Point map_location) {
144157 for (std::size_t cur_x = 2 ; cur_x < pixels.size ().width - 2 ; ++cur_x) {
@@ -158,9 +171,13 @@ Game make_lesson()
158171 retval.player = player;
159172
160173 retval.popup_message =
161- " Welcome to 'Learning C++ With Game Hacking Lesson 00!' Your job is to get into the special square in the bottom right "
162- " corner of the map. But to do that you'll need to modify the source code!" ;
174+ " Welcome to 'Learning C++ With Game Hacking Lesson 00'\n\n "
175+ " This lesson is to just get started with the project, but you will also learn some basic logic and how to get "
176+ " around the source code.\n\n "
177+ " Your job is to get into the special square in the bottom right corner of the map.\n\n "
178+ " But to do that you'll need to modify the source code!\n "
179+ " (Be sure to look for clues in the bottom message box :) )" ;
163180
164181 return retval;
165182}
166- }// namespace lefticus::my_awesome_game
183+ }// namespace lefticus::awesome_game::hacking::lesson_00
0 commit comments