From 28e83c72d579437ab7121c378dc8aed88ab9a048 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arvid=20Sj=C3=B6blom?= Date: Mon, 11 Dec 2023 10:05:33 +0100 Subject: [PATCH] cleanup GameOver_menu.cc --- src/GameOver_menu.cc | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/GameOver_menu.cc b/src/GameOver_menu.cc index 3a7cbaa..14e954a 100644 --- a/src/GameOver_menu.cc +++ b/src/GameOver_menu.cc @@ -66,14 +66,16 @@ GameOver_menu::GameOver_menu(int const points, json& params) : // Points text - pointstext = sf::Text{ "Your points: " + std::to_string(points), font, 30 }; + pointstext = sf::Text{ "Your points: " + std::to_string(points), font, 30}; sf::FloatRect gbp {pointstext.getGlobalBounds()}; pointstext.setOrigin(gbp.width / 2, gbp.height / 2); pointstext.setPosition (S_WIDTH / 2 , ((S_HEIGHT / 2) - 100)); pointstext.setFillColor(sf::Color::Black); // Fun fact - funfacttext = sf::Text{"You can buy: " + std::to_string(static_cast(points)/static_cast(79)) + " Kir!", font, 14 }; + funfacttext = sf::Text{"You can buy: " + + std::to_string(static_cast(points)/static_cast(79)) + + " Kir!", font, 14 }; sf::FloatRect gbff {funfacttext.getGlobalBounds()}; funfacttext.setOrigin(gbff.width / 2, gbff.height / 2); funfacttext.setPosition (S_WIDTH / 2 , ((S_HEIGHT / 2) - 70)); @@ -149,8 +151,10 @@ void GameOver_menu::update(Context& context) } // mouse placement - mouse_r.setPosition(((S_WIDTH / 2) + 60 - 30*(menu_index - 1)), ((S_HEIGHT / 2) + 80 + 50*(menu_index - 1))); - mouse_l.setPosition(((S_WIDTH / 2) - 58 + 30*(menu_index - 1)), ((S_HEIGHT / 2) + 80 + 50*(menu_index - 1))); + mouse_r.setPosition(((S_WIDTH / 2) + 60 - 30*(menu_index - 1)), + ((S_HEIGHT / 2) + 80 + 50*(menu_index - 1))); + mouse_l.setPosition(((S_WIDTH / 2) - 58 + 30*(menu_index - 1)), + ((S_HEIGHT / 2) + 80 + 50*(menu_index - 1))); } @@ -268,17 +272,25 @@ void GameOver_menu::text_input(sf::Event& event) void GameOver_menu::load_to_csv() { - std::string current_line{playerText.getString() + ", " + std::to_string(points)}; + std::string current_line{playerText.getString() + + ", " + std::to_string(points)}; - std::ifstream highscore_file_r{data["game_constants"]["highscore_file"].get()}; + std::ifstream highscore_file_r{ + data["game_constants"]["highscore_file"].get()}; std::vector lines_read; std::vector lines_write; - for (std::string one_line; std::getline(highscore_file_r, one_line);lines_read.push_back(one_line)); + for (std::string one_line; std::getline(highscore_file_r, one_line);) + { + lines_read.push_back(one_line); + } + bool added {false}; - for (std::string::size_type line_count{0}; line_count < lines_read.size(); line_count++) + for (std::string::size_type line_count{0}; + line_count < lines_read.size(); line_count++) { - if (!added && points > std::stoi(lines_read[line_count].substr(lines_read[line_count].find_first_of(',') + 1))) + if (!added && points > std::stoi(lines_read[line_count].substr( + lines_read[line_count].find_first_of(',') + 1))) { lines_write.push_back(current_line); added = true; @@ -292,12 +304,17 @@ void GameOver_menu::load_to_csv() } - if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back(); + if (lines_write.size() > data["game_constants"]["scoreboard"]) + { + lines_write.pop_back(); + } highscore_file_r.close(); - std::ofstream highscore_file_w{data["game_constants"]["highscore_file"].get()}; - for (std::string::size_type line_count{0}; line_count < lines_write.size(); highscore_file_w << lines_write[line_count++] << std::endl); + std::ofstream highscore_file_w{ + data["game_constants"]["highscore_file"].get()}; + for (std::string::size_type line_count{0}; line_count < lines_write.size(); + highscore_file_w << lines_write[line_count++] << std::endl); highscore_file_w.close(); } -- 2.30.2