-
Notifications
You must be signed in to change notification settings - Fork 3
Issue 15 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 15 #18
Conversation
- add lower() and upper() functions for std::strings - add print_enum_table for the main menu in anim.cpp - add assets_dir field to Manifest - add some brief doc strings
src/anim.cpp
Outdated
void print_frame(Pokemon& pkmn1, Pokemon& pkmn2) | ||
void print_splash_screen(const std::filesystem::path& assets_dir) | ||
{ | ||
auto logo = utils::read_file(assets_dir / std::filesystem::path("splashscreen.txt")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI: fs::path
can be implicitly constructed from string literals too: just assets_dir / "splashscreen.txt"
will work!
src/anim.cpp
Outdated
auto logo = utils::read_file(assets_dir / std::filesystem::path("splashscreen.txt")); | ||
std::cout << utils::style(std::accumulate(logo.begin(), logo.end(), std::string("")), utils::Color::YELLOW) << '\n'; | ||
|
||
std::cout << '\n' << std::string(19, ' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI: cout << setfill(18) << ' '
would avoid needing to construct a string, but length 19 is small enough to fit in SBOs on all compilers anyway.
for (const char& c : "copyright (c) 2021 cpp-gamedev") | ||
{ | ||
std::cout << c; | ||
utils::sleep(100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so this is the "splash screen" xD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shy beginnings xD
models::Pokemon player = pkmns[selection - 1]; | ||
|
||
// 4. remove selection from pkmns, so that player won't fight against his doppelganger | ||
pkmns.erase(std::remove_if(pkmns.begin(), pkmns.end(), [player](models::Pokemon pkmn) { return player.id == pkmn.id; }), pkmns.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erase remove idiom, nice!
src/anim.cpp
Outdated
return {player, pkmns.size() > 1 ? utils::random_choice(pkmns) : pkmns[0]}; | ||
} | ||
|
||
void print_frame(models::Pokemon& pkmn1, models::Pokemon& pkmn2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these parameters be const
?
src/main.cpp
Outdated
} | ||
else | ||
{ | ||
std::cerr << "Error!" << '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to print what the error was, so the player can try to fix it.
src/utils.cpp
Outdated
@@ -34,6 +38,18 @@ std::string style(std::string text, Color fore, Color back) | |||
return ansi_text.append(kt::format_str("{}\033[0m", text)); | |||
} | |||
|
|||
std::string upper(std::string& str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both upper
and lower
transform the string in place, so they shouldn't return anything.
template <typename T> | ||
std::vector<T> random_ranges(T min, T max, std::size_t k) | ||
{ | ||
std::vector<T> vector(k); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General suggestion if and when you don't need to return a vector: if you move k
to be another template parameter instead, you could use an array (or std::array
) and avoid vector heap allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed k
to typename U
, but I'll keep the return type as a vector for now. Will use an array in the future when I move these functions to their own library :)
+++ Update to the UI +++
Closes issue #15. Note that there are a few things that should be addressed in the future:
load_main_menu
configure_move_set
generates at least on move of typeMoveType::ATTACK
(else you or your opponent won't be able to inflict damage)Difficulty::HARD
hard to beat?)I intent to address the points above in my next PR.
For the first time ever, something noteworthy is happing in
main.cpp
:check_manifest
seems to be a solid safeguard against missing assets (so far)load_main_menu
enables user customization before the game startsprint_frame
is called for testing purposes, up until then everything should be in working orderI also added a
easy_install.sh
script for Linux users, but you may need to installapt-get python3-venv
if you never really have used Python before. Should reduce the number of commands one has to type in before the game starts by a fair share :)