cleanup GameOver_menu.cc
authorArvid Sjöblom <arvsj277@student.liu.se>
Mon, 11 Dec 2023 09:05:33 +0000 (10:05 +0100)
committerArvid Sjöblom <arvsj277@student.liu.se>
Mon, 11 Dec 2023 09:05:33 +0000 (10:05 +0100)
src/GameOver_menu.cc

index 3a7cbaaa3eb11072736b8c0eee36cadb2523a6b0..14e954a871df4eaeb2bbbc7e386c5c946a0f6573 100644 (file)
@@ -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<float>(points)/static_cast<float>(79)) + " Kir!", font, 14 };
+    funfacttext = sf::Text{"You can buy: " + 
+        std::to_string(static_cast<float>(points)/static_cast<float>(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::string>()};
+    std::ifstream highscore_file_r{
+        data["game_constants"]["highscore_file"].get<std::string>()};
     std::vector<std::string> lines_read;
     std::vector<std::string> 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<std::string>()};
-    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<std::string>()};
+    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();
 }