}
-void Map::update(int const points, int const game_time)
+void Map::update(int const collected, int const points, int const time_left)
{
- point_text.setString("Points: " + std::to_string(points) + "\n" + "Time left: " + std::to_string(game_time) + " s");
+ point_text.setString("Collected: " + std::to_string(collected) + "\n" + "Points: " + std::to_string(points) + "\n" + "Time left: " + std::to_string(time_left) + " s");
}
void Map::render(sf::RenderWindow& window) const
#include "json.hpp"
#include <fstream>
+#include <string>
+#include <vector>
#include <cmath>
using json = nlohmann::json;
bottle_texture.loadFromFile("assets/kir.png");
YF_texture.loadFromFile("assets/YF.png");
+ f.close();
}
void Game_state::update(Context &context)
int remaining_time {static_cast<int>(data["game_constants"]["game_time"]) - static_cast<int>(game_time)};
if (remaining_time < 0)
{
+ // LÄGG ALLT NEDAN I GAME OVER MENYN.
+ 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();
+
context.next_state = std::make_unique<Start_menu>();
return;
}
}
enemy->update(context);
- game_map->update(points, remaining_time);
+ game_map->update(player->get_collected(), points, remaining_time);
if (yf.size()>0)
{
for(unsigned int i {0}; i < yf.size(); ++i)
else if (menu)
{
context.next_state = std::make_unique<Start_menu>();
- context.saved_game.release();
+ context.saved_game.reset();
}
// changes color on text depending on selection