git repos / blockattack-game

commit 1f50b970

sago007 · 2015-12-30 21:00
1f50b97020ec9985031d2df51a317be9ac442086 patch · browse files
parent 1899da111bb25d8cbb283f2ecd0882c5b84e499e

Moved the highscore functions out

Changed files

M source/code/highscore.cpp before
M source/code/os.cpp before
M source/code/os.hpp before
diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index 74fe4e5..de94965 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp
@@ -22,50 +22,13 @@ http://blockattack.net
*/
#include "highscore.h"
+#include "os.hpp"
using namespace std;
-#ifdef _WIN32
-
-//Returns path to "my Documents" in windows:
-string getMyDocumentsPath1() {
- TCHAR pszPath[MAX_PATH];
- //if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) {
- if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) {
- // pszPath is now the path that you want
- cout << "MyDocuments Located: " << pszPath << endl;
- string theResult= pszPath;
- return theResult;
- }
- else {
- cout << "Warning: My Documents not found!" << endl;
- string theResult ="";
- return theResult;
- }
-}
-
-#endif
-
Highscore::Highscore(int type) {
-#if defined(__unix__)
- string home = getenv("HOME");
- string filename1 = home+"/.gamesaves/blockattack/endless.dat";
- string filename2 = home+"/.gamesaves/blockattack/timetrial.dat";
-#elif defined(_WIN32)
- string home = getMyDocumentsPath1();
- string filename1, filename2;
- if (&home!=nullptr) {
- filename1 = home+"/My Games/blockattack/endless.dat";
- filename2 = home+"/My Games/blockattack/timetrial.dat";
- }
- else {
- filename1 = "endless.dat";
- filename2 = "timetrial.dat";
- }
-#else
- string filename1 = "endless.dat";
- string filename2 = "timetrial.dat";
-#endif
+ string filename1 = getPathToHighscoresEndless();
+ string filename2 = getPathToHighscoresTimetrial();
ourType = type;
if (type == 1) {
filename = filename1;
@@ -91,25 +54,8 @@ Highscore::Highscore(int type) {
}
void Highscore::writeFile() {
-#if defined(__unix__)
- string home = getenv("HOME");
- string filename1 = home+"/.gamesaves/blockattack/endless.dat";
- string filename2 = home+"/.gamesaves/blockattack/timetrial.dat";
-#elif defined(_WIN32)
- string home = getMyDocumentsPath1();
- string filename1, filename2;
- if (&home!=nullptr) {
- filename1 = home+"/My Games/blockattack/endless.dat";
- filename2 = home+"/My Games/blockattack/timetrial.dat";
- }
- else {
- filename1 = "endless.dat";
- filename2 = "timetrial.dat";
- }
-#else
- string filename1 = "endless.dat";
- string filename2 = "timetrial.dat";
-#endif
+ string filename1 = getPathToHighscoresEndless();
+ string filename2 = getPathToHighscoresTimetrial();
if (ourType == 1) {
filename = filename1;
}
diff --git a/source/code/os.cpp b/source/code/os.cpp index c9cf5a8..8e509ed 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp
@@ -51,6 +51,23 @@ string getMyDocumentsPath() {
}
}
+//Returns path to "my Documents" in windows:
+string getMyDocumentsPath1() {
+ TCHAR pszPath[MAX_PATH];
+ //if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) {
+ if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) {
+ // pszPath is now the path that you want
+ cout << "MyDocuments Located: " << pszPath << endl;
+ string theResult= pszPath;
+ return theResult;
+ }
+ else {
+ cout << "Warning: My Documents not found!" << endl;
+ string theResult ="";
+ return theResult;
+ }
+}
+
#endif
/**
@@ -67,4 +84,12 @@ std::string getPathToSaveFiles() {
#else
return ".";
#endif
+}
+
+std::string getPathToHighscoresEndless() {
+ return getPathToSaveFiles()+"/endless.dat";
+}
+
+std::string getPathToHighscoresTimetrial() {
+ return getPathToSaveFiles()+"/timetrial.dat";
}
\ No newline at end of file
diff --git a/source/code/os.hpp b/source/code/os.hpp index 156f039..3b02f19 100644 --- a/source/code/os.hpp +++ b/source/code/os.hpp
@@ -30,4 +30,7 @@ http://blockattack.net
std::string getPathToSaveFiles() __attribute__((pure));
#if defined(_WIN32)
std::string getMyDocumentsPath();
-#endif
\ No newline at end of file
+#endif
+
+std::string getPathToHighscoresEndless();
+std::string getPathToHighscoresTimetrial();