diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index b0e5920..bfb90e5 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -33,6 +33,7 @@ http://blockattack.sf.net #include "BlockGame.hpp" #include "puzzlehandler.hpp" +#include "stageclearhandler.hpp" #include @@ -1738,39 +1739,12 @@ void BlockGame::AI_Move() { //Updates evrything, if not called nothing happends void BlockGame::Update() { - Uint32 tempUInt32; Uint32 nowTime = ticks; //We remember the time, so it doesn't change during this call { FindTowerHeight(); if ((linesCleared-TowerHeight>stageClearLimit) && (stageClear) && (!bGameOver)) { - stageCleared[Level] = true; - if (stageScores[Level](&tempBool), sizeof(bool)); - } - for (int i=0; i(&tempUInt32), sizeof(Uint32)); - } - for (int i=0; i(&tempUInt32), sizeof(Uint32)); - } - outfile.close(); - } + StageClearSetClear(Level, score, nowTime-gameStartedAt); setPlayerWon(); stageButtonStatus = SBstageClear; } diff --git a/source/code/Makefile b/source/code/Makefile index 99e464c..8abfe69 100644 --- a/source/code/Makefile +++ b/source/code/Makefile @@ -50,7 +50,8 @@ endif BASE_LIBS += -lphysfs -OFILES=main.o highscore.o ReadKeyboard.o joypad.o listFiles.o common.o stats.o Libs/NFont.o Libs/SDL_FontCache.o MenuSystem.o menudef.o puzzlehandler.o ${SAGO_O_FILES} +OFILES=main.o highscore.o ReadKeyboard.o joypad.o listFiles.o common.o stats.o Libs/NFont.o Libs/SDL_FontCache.o MenuSystem.o menudef.o \ + puzzlehandler.o stageclearhandler.o ${SAGO_O_FILES} ifeq ($(CROSS),i686-w64-mingw32.static-) OFILES += winicon.res diff --git a/source/code/main.cpp b/source/code/main.cpp index 6a65aa0..f05c060 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -56,6 +56,7 @@ http://blockattack.sf.net #include #include "MenuSystem.h" #include "puzzlehandler.hpp" +#include "stageclearhandler.hpp" #include #include @@ -1536,9 +1537,7 @@ int PuzzleLevelSelect(int Type) { int oldmousex = 0; int oldmousey = 0; bool levelSelected = false; - bool tempBool; int nrOfLevels = 0; - Uint32 tempUInt32; Uint32 totalScore = 0; Uint32 totalTime = 0; int selected = 0; @@ -1555,46 +1554,10 @@ int PuzzleLevelSelect(int Type) { nrOfLevels = PuzzleGetNumberOfPuzzles(); } if (Type == 1) { - ifstream stageFile(stageClearSavePath.c_str(),ios::binary); - if (stageFile) { - for (int i = 0; i(&tempBool),sizeof(bool)); - stageCleared[i]=tempBool; - } - if (!stageFile.eof()) { - for (int i=0; i(&tempUInt32),sizeof(Uint32)); - } - stageScores[i]=tempUInt32; - totalScore+=tempUInt32; - } - for (int i=0; i(&tempUInt32),sizeof(Uint32)); - } - stageTimes[i]=tempUInt32; - totalTime += tempUInt32; - } - } - else { - for (int i=0; i0) { - scoreString = _("Best score: ")+itoa(stageScores.at(selected)); + if (GetStageScores(selected)>0) { + scoreString = _("Best score: ")+itoa(GetStageScores(selected)); } - if (stageTimes.at(selected)>0) { - timeString = _("Time used: ")+itoa(stageTimes.at(selected)/1000/60)+" : "+itoa2((stageTimes.at(selected)/1000)%60); + if (GetStageTime(selected)>0) { + timeString = _("Time used: ")+itoa(GetStageTime(selected)/1000/60)+" : "+itoa2((GetStageTime(selected)/1000)%60); } NFont_Write(screen, 200,200,scoreString.c_str()); diff --git a/source/code/mainVars.hpp b/source/code/mainVars.hpp index 9e28c16..007a0ec 100644 --- a/source/code/mainVars.hpp +++ b/source/code/mainVars.hpp @@ -195,13 +195,6 @@ static const int bsize = 50; std::string player1name; std::string player2name; -//paths -static std::string stageClearSavePath; - -static const int nrOfStageLevels = 50; //number of stages in stage Clear -std::vector stageCleared(nrOfStageLevels); //vector that tells if a stage is cleared -std::vector stageTimes(nrOfStageLevels); //For statistical puposes -std::vector stageScores(nrOfStageLevels); //--||-- bool twoPlayers; //True if two players are playing //Old mouse position: diff --git a/source/code/stageclearhandler.cpp b/source/code/stageclearhandler.cpp new file mode 100644 index 0000000..d57d656 --- /dev/null +++ b/source/code/stageclearhandler.cpp @@ -0,0 +1,121 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +#include "stageclearhandler.hpp" +#include "SDL.h" +#include +#include +#include + +//paths +std::string stageClearSavePath; + + +std::vector stageCleared(nrOfStageLevels); //vector that tells if a stage is cleared +std::vector stageTimes(nrOfStageLevels); //For statistical puposes +std::vector stageScores(nrOfStageLevels); //--||-- +Uint32 totalScore = 0; +Uint32 totalTime = 0; + +using namespace std; + +void StageClearSetClear(int Level, int score, int time) { + stageCleared[Level] = true; + int gameEndedAfter = time; + if (stageScores[Level](&tempBool), sizeof(bool)); + } + for (int i=0; i(&tempUInt32), sizeof(Uint32)); + } + for (int i=0; i(&tempUInt32), sizeof(Uint32)); + } + outfile.close(); + } +} + +void LoadStageClearStages() { + bool tempBool; + Uint32 tempUInt32; + ifstream stageFile(stageClearSavePath.c_str(),ios::binary); + if (stageFile) { + for (int i = 0; i(&tempBool),sizeof(bool)); + stageCleared[i]=tempBool; + } + if (!stageFile.eof()) { + for (int i=0; i(&tempUInt32),sizeof(Uint32)); + } + stageScores[i]=tempUInt32; + totalScore+=tempUInt32; + } + for (int i=0; i(&tempUInt32),sizeof(Uint32)); + } + stageTimes[i]=tempUInt32; + totalTime += tempUInt32; + } + } + else { + for (int i=0; i + +extern std::string stageClearSavePath; + +void StageClearSetClear(int level, int score, int time); +void LoadStageClearStages(); +int GetTotalScore(); +int GetTotalTime(); +int GetNrOfLevels(); +bool IsStageCleared(int level); +int GetStageScores(int level); +int GetStageTime(int level); + +const int nrOfStageLevels = 50; //number of stages in stage Clear + +#endif /* STAGECLEARHANDLER_HPP */ +