Skip to content

Commit 29224bc

Browse files
committed
Add suggested changes to the code base.
1 parent bb48036 commit 29224bc

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

src/anim.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void print_splash_screen(const std::filesystem::path& assets_dir)
4444
for (const char& c : "copyright (c) 2021 cpp-gamedev")
4545
{
4646
std::cout << c;
47-
utils::sleep(100);
47+
utils::sleep(std::chrono::milliseconds{50});
4848
}
4949
}
5050

@@ -88,7 +88,7 @@ void print_move_table(const models::Pokemon& pkmn)
8888
std::array<models::Pokemon, 2> load_main_menu(const utils::Manifest& manifest)
8989
{
9090
// 1. set difficulty
91-
int selection{utils::validate_user_input({"easy", "moderate", "hard"}, "(1/2) set difficulty")};
91+
int selection{utils::validate_user_input({"easy", "moderate", "hard"}, "(1/2) SET DIFFICULTY")};
9292
auto difficulty = (selection == 1) ? models::Difficulty::EASY : (selection == 2) ? models::Difficulty::MODERATE : models::Difficulty::HARD;
9393

9494
// 2. instantiate all available pokemons
@@ -101,7 +101,7 @@ std::array<models::Pokemon, 2> load_main_menu(const utils::Manifest& manifest)
101101
std::vector<std::string> names{};
102102
names.reserve(pkmns.size());
103103
std::for_each(pkmns.begin(), pkmns.end(), [&names](models::Pokemon& pkmn) { names.push_back(pkmn.name); });
104-
selection = utils::validate_user_input(names, "(2/2) choose a pokemon");
104+
selection = utils::validate_user_input(names, "(2/2) CHOOSE A POKEMON");
105105
models::Pokemon player = pkmns[selection - 1];
106106

107107
// 4. remove selection from pkmns, so that player won't fight against his doppelganger

src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using namespace utils;
88

99
int main()
1010
{
11+
constexpr std::chrono::milliseconds delay{1000};
1112
const auto assets_dir = find_upwards("assets");
1213
Manifest manifest = check_manifest(assets_dir.parent_path() / "manifest.json");
1314

@@ -26,15 +27,15 @@ int main()
2627

2728
if (ai.hp > 0)
2829
{
29-
sleep(1000);
30+
sleep(delay);
3031
ai.make_move(player, random_range<std::size_t>(1, 4));
3132
clear_screen();
3233
}
3334

3435
}
3536

3637
clear_screen();
37-
slow_print((ai.hp == 0) ? "You Won :)" : "You Lost :(", 50);
38+
slow_print((ai.hp == 0) ? "You Won :)" : "You Lost :(", delay / 20);
3839

3940
return EXIT_SUCCESS;
4041
}

src/models.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ void Pokemon::make_move(Pokemon& pkmn, std::size_t index)
131131
break;
132132
}
133133

134-
utils::slow_print(msg, 50);
134+
utils::slow_print(msg, std::chrono::milliseconds{50});
135135
}
136136
} // namespace models

src/models.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ struct Move
2929

3030
enum class Difficulty
3131
{
32-
EASY = 1,
33-
MODERATE = 2,
34-
HARD = 3
32+
NONE,
33+
EASY,
34+
MODERATE,
35+
HARD
3536
};
3637

3738
struct Pokemon

src/utils.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ void clear_screen()
1313
std::cout << "\033[2J\033[1;1H";
1414
}
1515

16-
void sleep(int ms)
16+
void sleep(std::chrono::milliseconds ms)
1717
{
18-
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
18+
std::this_thread::sleep_for(ms);
1919
}
2020

21-
void slow_print(std::string str, int ms)
21+
void slow_print(const std::string& str, std::chrono::milliseconds ms)
2222
{
23-
for (const char& c : str)
23+
for (char c : str)
2424
{
2525
std::cout << c;
2626
sleep(ms);
@@ -86,7 +86,7 @@ std::vector<std::string> read_file(const std::filesystem::path& path)
8686
return lines;
8787
}
8888

89-
void print_enum_table(std::vector<std::string> table, std::string header)
89+
void print_enum_table(const std::vector<std::string>& table, const std::string& header)
9090
{
9191
// +----------------------------------------------------------+
9292
// | HEADER |
@@ -101,7 +101,6 @@ void print_enum_table(std::vector<std::string> table, std::string header)
101101
std::string horizontal_line = utils::style(std::string("+").append(std::string(width - 2, '-')).append("+"), border_color);
102102

103103
std::cout << horizontal_line << '\n';
104-
upper(header);
105104
std::cout << border << kt::format_str(" {}{}", header, std::string(width - 3 - header.length(), ' ')) << border << '\n';
106105

107106
// clang-format off
@@ -112,7 +111,6 @@ void print_enum_table(std::vector<std::string> table, std::string header)
112111

113112
for (std::size_t i = 0; i < table.size(); ++i)
114113
{
115-
lower(table[i]);
116114
std::cout << padded_string(i + 1, table[i], border) << '\n';
117115
}
118116

@@ -151,7 +149,7 @@ Manifest check_manifest(const std::filesystem::path& path)
151149
manifest.game_ready = json["game_ready"].as<bool>();
152150
manifest.duplicates = json["duplicates"].as<std::vector<int>>();
153151
manifest.files = json["files"].as<std::vector<std::string>>();
154-
manifest.asset_dir = path.parent_path() / std::filesystem::path("assets");
152+
manifest.asset_dir = path.parent_path() / "assets";
155153
}
156154
}
157155
else

src/utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ T get_user_input(std::string prompt)
7474

7575
void clear_screen();
7676

77-
void sleep(int ms);
77+
void sleep(std::chrono::milliseconds ms);
7878

79-
void slow_print(std::string str, int ms);
79+
void slow_print(const std::string& str, std::chrono::milliseconds ms);
8080

8181
enum class Color
8282
{
@@ -100,7 +100,7 @@ std::filesystem::path find_upwards(std::string dir_name, int max_depth = 10);
100100

101101
std::vector<std::string> read_file(const std::filesystem::path& path);
102102

103-
void print_enum_table(std::vector<std::string> table, std::string header);
103+
void print_enum_table(const std::vector<std::string>& table, const std::string& header);
104104

105105
int validate_user_input(std::vector<std::string> table, std::string header);
106106

0 commit comments

Comments
 (0)