#include <string>
#include <fstream>
#include <vector>
+#include <cmath>
#include "States.h"
#include "Context.h"
// mouse placement
mouse_r.setPosition(((S_WIDTH / 2) + 60), ((S_HEIGHT / 2) - 45 + 50*(menu_index - 1)));
mouse_l.setPosition(((S_WIDTH / 2) - 58), ((S_HEIGHT / 2) + 2 + 50*(menu_index - 1)));
-
- //spara namn till fil
- std::string current_line{"Gorilla," + std::to_string(points)};
-
- std::ifstream highscore_file_r{"assets/highscore.csv"};
- 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));
-
- bool added {false};
- 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)))
- {
- std::cout << "i loop" << std::endl;
- lines_write.push_back(current_line);
- added = true;
- }
- lines_write.push_back(lines_read[line_count]);
- }
-
- if (!added) lines_write.push_back(current_line);
-
-
-
- if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back();
-
- highscore_file_r.close();
-
- std::ofstream highscore_file_w{"assets/highscore.csv"};
- 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();
}
if(menu_index == 1)
{
+ load_to_csv();
menu = true;
menu_index = 1;
}
playerInput += event.text.unicode;
playerText.setString(playerInput);
}
+
+
}
+
+//spara namn till fil
+void GameOver_menu::load_to_csv() const
+{
+ std::string current_line{"Gorilla," + std::to_string(points)};
+
+ std::ifstream highscore_file_r{"assets/highscore.csv"};
+ 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));
+
+ bool added {false};
+ 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)))
+ {
+ std::cout << "i loop" << std::endl;
+ lines_write.push_back(current_line);
+ added = true;
+ }
+ lines_write.push_back(lines_read[line_count]);
+ }
+
+ if (!added) lines_write.push_back(current_line);
+
+
+
+ if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back();
+
+ highscore_file_r.close();
+
+ std::ofstream highscore_file_w{"assets/highscore.csv"};
+ 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();
+}
\ No newline at end of file