26 lines
1.1 KiB
C++
26 lines
1.1 KiB
C++
// Scores.h - High score persistence manager
|
|
#pragma once
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
struct ScoreEntry { int score{}; int lines{}; int level{}; double timeSec{}; std::string name{"PLAYER"}; std::string gameType{"classic"}; };
|
|
|
|
class ScoreManager {
|
|
public:
|
|
explicit ScoreManager(size_t maxScores = 12);
|
|
void load();
|
|
void save() const;
|
|
// Replace the in-memory scores (thread-safe caller should ensure non-blocking)
|
|
void replaceAll(const std::vector<ScoreEntry>& newScores);
|
|
// New optional `gameType` parameter will be sent as `game_type`.
|
|
// Allowed values: "classic", "versus", "cooperate", "challenge".
|
|
void submit(int score, int lines, int level, double timeSec, const std::string& name = "PLAYER", const std::string& gameType = "classic");
|
|
bool isHighScore(int score) const;
|
|
const std::vector<ScoreEntry>& all() const { return scores; }
|
|
private:
|
|
std::vector<ScoreEntry> scores;
|
|
size_t maxEntries;
|
|
std::string filePath() const; // resolve path (SDL pref path or local)
|
|
void createSampleScores(); // create sample high scores
|
|
};
|