git repos / blockattack-game

commit dcdbd31f

Poul Sander · 2025-04-04 18:45
dcdbd31fd36fef48fd70c6a65761ded6c52b71c4 patch · browse files
parent a80f6a784de9bc6d8edda0fcd2057f4ac0e04985

Add Save feature for the puzzle file

Changed files

M source/code/puzzlehandler.cpp before
M source/code/puzzlehandler.hpp before
diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp index 90a2fff..0550453 100644 --- a/source/code/puzzlehandler.cpp +++ b/source/code/puzzlehandler.cpp
@@ -123,3 +123,21 @@ int LoadPuzzleStages( ) {
LoadClearData();
return 0;
}
+
+int SavePuzzleStages() {
+ if (puzzleName.length() == 0) {
+ std::cerr << "Error: No puzzle name set. Cannot save.\n";
+ return -1;
+ }
+ std::string fileContent = std::to_string(nrOfPuzzles) + "\n";
+ for (int k=0; k<nrOfPuzzles ; k++) {
+ fileContent += std::to_string(nrOfMovesAllowed.at(k)) + "\n";
+ for (int i=11; i>=0; i--)
+ for (int j=0; j<6; j++) {
+ fileContent += std::to_string(puzzleLevels[k][j][i]) + " ";
+ }
+ fileContent += "\n";
+ }
+ sago::WriteFileContent(((std::string)("puzzles/"+puzzleName)).c_str(), fileContent);
+ return 0;
+}
\ No newline at end of file
diff --git a/source/code/puzzlehandler.hpp b/source/code/puzzlehandler.hpp index 5048b41..a557c6d 100644 --- a/source/code/puzzlehandler.hpp +++ b/source/code/puzzlehandler.hpp
@@ -31,6 +31,7 @@ int PuzzleNumberOfMovesAllowed(int level);
int PuzzleGetBrick(int level, int x, int y);
bool PuzzleIsCleared(int level);
int LoadPuzzleStages();
+int SavePuzzleStages();
int PuzzleGetNumberOfPuzzles();
void PuzzleSetClear(int level);
const std::string& PuzzleGetName();