diff --git a/source/code/main.cpp b/source/code/main.cpp index dc5361f..ed3bf76 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -2823,7 +2823,7 @@ static void MakeBackground(int xsize, int ysize, BlockGame *theGame) //The function that allows the player to choose PuzzleLevel -int PuzzleLevelSelect() +int PuzzleLevelSelect(int Type) { const int xplace = 200; const int yplace = 300; @@ -2831,30 +2831,87 @@ int PuzzleLevelSelect() int levelNr, mousex, mousey, oldmousex, oldmousey; bool levelSelected = false; bool tempBool; + int nrOfLevels; + Uint32 tempUInt32; + Uint32 totalScore = 0; + Uint32 totalTime = 0; int selected = 0; //Loads the levels, if they havn't been loaded: - LoadPuzzleStages(); + if(Type == 0) + LoadPuzzleStages(); //Keeps track of background; int nowTime=SDL_GetTicks(); - ifstream puzzleFile(puzzleSavePath.c_str(),ios::binary); MakeBackground(xsize,ysize); - if (puzzleFile) - { - for (int i=0; (i(&tempBool),sizeof(bool)); + puzzleCleared[i] = tempBool; + } + puzzleFile.close(); + } + else { - puzzleFile.read(reinterpret_cast(&tempBool),sizeof(bool)); - puzzleCleared[i] = tempBool; + tempBool = false; + 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= nrOfPuzzles) + if(selected >= nrOfLevels) selected = 0; - cout << "Selected: "<< selected << endl; } if ( event.key.keysym.sym == SDLK_LEFT ) { --selected; if(selected < 0) - selected = nrOfPuzzles; - cout << "Selected: "<< selected << endl; + selected = nrOfLevels-1; } if ( event.key.keysym.sym == SDLK_DOWN ) { selected+=10; - if(selected >= nrOfPuzzles) + if(selected >= nrOfLevels) selected-=10; - cout << "Selected: "<< selected << endl; } if ( event.key.keysym.sym == SDLK_UP ) { selected-=10; if(selected < 0) selected+=10; - cout << "Selected: "<< selected << endl; } } @@ -2924,7 +2981,7 @@ int PuzzleLevelSelect() { int tmpSelected = -1; int j; - for (j = 0; (j0) + scoreString = _("Best score: ")+itoa(stageScores.at(selected)); + if(stageTimes.at(selected)>0) + timeString = _("Time used: ")+itoa(stageTimes.at(selected)/1000/60)+" : "+itoa2((stageTimes.at(selected)/1000)%60); + + NFont_Write(screen, 200,200,scoreString.c_str()); + NFont_Write(screen, 200,250,timeString.c_str()); + string totalString = (format("Total score: %1% in %2%:%3%")%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str(); //"Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60); + NFont_Write(screen, 200,600,totalString.c_str()); + } //DrawIMG(mouse,screen,mousex,mousey); mouse.PaintTo(screen,mousex,mousey); @@ -2975,7 +3048,7 @@ int PuzzleLevelSelect() } //The function that allows the player to choose Level number -int StageLevelSelect() +/*int StageLevelSelect() { const int xplace = 200; const int yplace = 300; @@ -3127,7 +3200,7 @@ int StageLevelSelect() while (!levelSelected); DrawIMG(background, screen, 0, 0); return levelNr; -} +}*/ //Ask user for what AI level he will compete agains, return the number. Number must be 0..AIlevels /*int startSingleVs() @@ -3430,7 +3503,7 @@ void StartSinglePlayerTimeTrial() int StartSinglePlayerPuzzle(int level) { - int myLevel = PuzzleLevelSelect(); + int myLevel = PuzzleLevelSelect(0); if(myLevel == -1) return 1; player1->NewPuzzleGame(myLevel,50,100,SDL_GetTicks()); @@ -4052,6 +4125,23 @@ int runGame(int gametype, int level) case 1: StartSinglePlayerTimeTrial(); break; + case 2: + { + int myLevel = PuzzleLevelSelect(1); + if(myLevel == -1) + return 1; + theGame.NewStageGame(myLevel,50,100,SDL_GetTicks()); + MakeBackground(xsize,ysize,&theGame,&theGame2); + DrawIMG(background, screen, 0, 0); + closeAllMenus(); + twoPlayers =false; + theGame2.SetGameOver(); + showGame = true; + vsMode = false; + strcpy(theGame.name, player1name); + strcpy(theGame2.name, player2name); + } + break; case 3: if(StartSinglePlayerPuzzle(level)) return 1; @@ -4278,7 +4368,7 @@ int runGame(int gametype, int level) if ((!showOptions)) #endif { - int myLevel = StageLevelSelect(); + int myLevel = PuzzleLevelSelect(1); theGame.NewStageGame(myLevel,50,100,SDL_GetTicks()); MakeBackground(xsize,ysize,&theGame,&theGame2); DrawIMG(background, screen, 0, 0); @@ -4321,7 +4411,7 @@ int runGame(int gametype, int level) if ((!showOptions)) #endif { - int myLevel = PuzzleLevelSelect(); + int myLevel = PuzzleLevelSelect(0); theGame.NewPuzzleGame(myLevel,50,100,SDL_GetTicks()); MakeBackground(xsize,ysize,&theGame,&theGame2); DrawIMG(background, screen, 0, 0); diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 48bc5bb..7c572b9 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -114,6 +114,11 @@ void runSinglePlayerTimeTrial(Button* b) runGame(1,0); } +void runStageClear(Button* b) +{ + runGame(2,0); +} + void runSinglePlayerPuzzle(Button* b) { runGame(3,0); @@ -263,11 +268,13 @@ void MainMenu() { InitMenues(); Menu m(&screen,_("Block Attack - Rise of the blocks"),false); - Button bHi,bTimetrial1, bPuzzle, bVs1, bConfigure,bHighscore; + Button bHi,bTimetrial1, bStageClear, bPuzzle, bVs1, bConfigure,bHighscore; bHi.setLabel(_("Single player - endless") ); bHi.setAction(runSinglePlayerEndless); bTimetrial1.setLabel(_("Single player - time trial") ); bTimetrial1.setAction(runSinglePlayerTimeTrial); + bStageClear.setLabel(_("Single player - stage clear") ); + bStageClear.setAction(runStageClear); bPuzzle.setLabel(_("Single player - puzzle mode") ); bPuzzle.setAction(runSinglePlayerPuzzle); bVs1.setLabel(_("Single player - vs") ); @@ -278,6 +285,7 @@ void MainMenu() bHighscore.setAction(buttonActionHighscores); m.addButton(&bHi); m.addButton(&bTimetrial1); + m.addButton(&bStageClear); m.addButton(&bPuzzle); m.addButton(&bVs1); m.addButton(&bConfigure);