git repos / blockattack-game

commit b5321636

sago007 · 2019-02-09 18:47
b53216363af12b4a7921c1634e7902d0bffaa3fd patch · browse files
parent 38fbf4d75f032ad63038e0599d71dfc1209afb94

Save the highscores to seperate files

Changed files

M source/code/BlockGame.hpp before
M source/code/highscore.cpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index db90d9b..2b272c3 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -261,6 +261,7 @@ public:
int getLevel() const;
bool GetAIenabled() const;
bool IsNearDeath() const;
+ double GetBaseSpeed() const { return baseSpeed; }
const BlockGameInfo& GetBlockGameInfo() {
return replayInfo;
}
diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index b37d5f5..758177f 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp
@@ -28,6 +28,7 @@ https://blockattack.net
#include "cereal/archives/json.hpp"
#include "sago/SagoMisc.hpp"
#include <algorithm>
+#include "common.h"
namespace cereal {
@@ -51,6 +52,13 @@ bool record_sorter (const record& i,const record& j) {
}
Highscore::Highscore(const std::string& type, double speed) : filename(type+".json.dat"), type(type), speed(speed) {
+ if (speed < 0.4) {
+ std::string old_locale = setlocale (LC_NUMERIC, nullptr);
+ setlocale (LC_NUMERIC, "C");
+ //Use special filenames for higher speeds (higher speed = lower number)
+ filename = SPrintStringF("%s_%.4f.json.dat", type.c_str(), speed);
+ setlocale(LC_NUMERIC, old_locale.c_str());
+ }
std::string readFileContent = sago::GetFileContent(filename.c_str());
if (readFileContent.length() > 0) {
try {
diff --git a/source/code/main.cpp b/source/code/main.cpp index 784483a..3b5c601 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1205,8 +1205,7 @@ int main(int argc, char* argv[]) {
}
int runGame(Gametype gametype, int level) {
- Highscore theTopScoresEndless = Highscore("endless", 0.5);
- Highscore theTopScoresTimeTrial = Highscore("timetrial", 0.5);
+ Highscore theTopScoresTimeTrial = Highscore("timetrial", 0.5);
drawBalls = true;
puzzleLoaded = false;
bool bNearDeath = false; //Play music faster or louder while tru
@@ -1733,6 +1732,7 @@ int runGame(Gametype gametype, int level) {
theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
}
if (theGame.isGameOver() && registerEndlessHighscore) {
+ Highscore theTopScoresEndless = Highscore("endless", theGame.GetBaseSpeed());
registerEndlessHighscore = false;
theTopScoresEndless.addScore(theGame.name, theGame.GetScore());
theGame.EndlessHighscoreEvent();