#pragma once #ifndef SNAKE_HIGHSCOREMANAGER_HXX #define SNAKE_HIGHSCOREMANAGER_HXX #include #include #include #include #include #include #include struct Score final { std::string player_name_; unsigned points_; template void serialize(Archive& archive, unsigned const version) { (void) version; archive & player_name_; archive & points_; } }; BOOST_CLASS_VERSION(Score, 0); struct HighScores final { std::vector scores_; template void serialize(Archive& archive, unsigned const version) { (void) version; archive & scores_; } }; BOOST_CLASS_VERSION(HighScores, 0); class HighScoreManager final : private boost::noncopyable { public: static int constexpr MAX_SCORES = 10; void set_new_score(unsigned score); [[nodiscard]] bool has_new_score() const; void provide_name_for_new_score(std::string const& name); static HighScoreManager& instance(); private: HighScoreManager(); void load(); void save() const; std::string data_dir_; HighScores high_score_; std::optional new_score_; }; #endif // SNAKE_HIGHSCOREMANAGER_HXX