-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsave_data.hpp
50 lines (38 loc) · 1.69 KB
/
save_data.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <utility>
#ifndef LR_SUPERFLAPPYBIRDS_SETTINGS_HPP
#define LR_SUPERFLAPPYBIRDS_SETTINGS_HPP
#include <chrono>
#include <fstream>
#include <iostream>
#include <vector>
struct HighScoreRow {
std::string name;
int score;
std::chrono::time_point<std::chrono::system_clock> time;
HighScoreRow(std::string name, int score, std::chrono::time_point<std::chrono::system_clock> time) :
name(std::move(name)), score(score), time(time) {}
};
class SaveData {
public:
static const int MAX_SCORES = 10;
std::vector<HighScoreRow> top_scores;
std::string filename = "superflappybirds_highscores.dat";
explicit SaveData(std::string config_folder_path);
void Serialize();
void Deserialize();
/// Adds a new high scorer to the list in the correct order.
/// \param name The player's name.
/// \param score The player's score.
/// \param time The time the player made the high score.
/// \return True if the entry was added, false otherwise.
bool AddNewScore(std::string name, int score, std::chrono::time_point<std::chrono::system_clock> *time = nullptr);
/// Determines how many of the players provided would get onto the high score table.
/// \param scores The scores for the players, needs to be in order from lowest to highest.
/// \return The number of players that would be added to the high score table.
int DoesPlayerQualifyForHighScoreTable(const std::vector<int> &scores);
bool DoesPlayerQualifyForHighScoreTable(int score);
/// Gets the highest score in the game so far.
/// \return The highest score
int HighScore();
};
#endif //LR_SUPERFLAPPYBIRDS_SETTINGS_HPP