From 0fb6c56cd42e0558717a264442436af02441abfb Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 28 Aug 2013 19:26:14 -0400 Subject: Added ability to add highscores to local highscore list --- gamestate.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'gamestate.cpp') diff --git a/gamestate.cpp b/gamestate.cpp index 323cac5..812f26c 100644 --- a/gamestate.cpp +++ b/gamestate.cpp @@ -4,6 +4,8 @@ #include "mazeoflife.h" #include "highscore.h" #include "titlestate.h" +#include +#include "hslist.h" class GameBoard { public: @@ -214,7 +216,48 @@ State* PlayGameState::operator() (SDL_Renderer* renderer) } case SDLK_ESCAPE: - return new TitleState(); + std::ifstream exists(getDataFile()); + if (exists) + { + FILE* hslist = fopen(getDataFile(), "r"); + int scores; + Highscore* h; + + fscanf(hslist, "%d%*c", &scores); + + if (scores < 10) + { + fclose(hslist); + + return new EnterHighscoreState(level); + } else { + for (int i=0; igetLevel() < level) + { + return new EnterHighscoreState(level); + } else { + return new DisplayAndReturnLocalHighscoreListState(); + } + } + } else { + return new EnterHighscoreState(level); + } } } } -- cgit 1.4.1