Skip to content

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

Merged
merged 15 commits into from
Jun 1, 2021
Merged

Issue 15 #18

merged 15 commits into from
Jun 1, 2021

Conversation

hentai-chan
Copy link
Contributor

@hentai-chan hentai-chan commented May 29, 2021

+++ Update to the UI +++

Closes issue #15. Note that there are a few things that should be addressed in the future:

  • catch invalid user selection in load_main_menu
  • ensure that configure_move_set generates at least on move of type MoveType::ATTACK (else you or your opponent won't be able to inflict damage)
  • balance difficulty (is 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:

  1. check_manifest seems to be a solid safeguard against missing assets (so far)
  2. there's a splash screen, very similar to my hangman game
  3. load_main_menu enables user customization before the game starts
  4. print_frame is called for testing purposes, up until then everything should be in working order

I also added a easy_install.sh script for Linux users, but you may need to install apt-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 :)

@hentai-chan hentai-chan added the enhancement New feature or request label May 29, 2021
@hentai-chan hentai-chan added this to the Finish Project milestone May 29, 2021
@hentai-chan hentai-chan linked an issue May 29, 2021 that may be closed by this pull request
2 tasks
@hentai-chan hentai-chan marked this pull request as ready for review May 30, 2021 22:58
@hentai-chan hentai-chan requested a review from karnkaul May 30, 2021 22:58
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"));
Copy link
Member

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, ' ');
Copy link
Member

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);
Copy link
Member

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

Copy link
Contributor Author

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());
Copy link
Member

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)
Copy link
Member

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';
Copy link
Member

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)
Copy link
Member

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);
Copy link
Member

@karnkaul karnkaul May 31, 2021

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.

Copy link
Contributor Author

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 :)

@hentai-chan hentai-chan merged commit 506dd9d into integration Jun 1, 2021
@hentai-chan hentai-chan deleted the issue-15 branch June 1, 2021 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preview Screen and Move Selection
2 participants