The score counting now stops during pauses
[ghostsoverboard] / seascene.cpp
index ee4c334..cf14094 100644 (file)
@@ -241,10 +241,6 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
         connect(pOctopus,SIGNAL(droppingGhosts()),pShip,SLOT(dropAllGhosts()));
     }
     delete pPosition;
-
-    scoreCounter_.start();
-
-
 }
 
 void SeaScene::setupMap(Level level)
@@ -378,6 +374,8 @@ void SeaScene::pause(bool paused)
             if (pPausetextItem_)
                 pPausetextItem_->hide();
 
+            scoreCounter_.start();
+
             autopauseTimer.start(); //Start counting towards autopause
             deviceLockPollTimer_.start(); //Start polling whether device is locked
         }
@@ -395,6 +393,8 @@ void SeaScene::pause(bool paused)
             }
 //                else qDebug() << "No pause text available";
 
+            levelScore_ += scoreCounter_.elapsed();
+
             autopauseTimer.stop(); //No need to count toward autopause when already paused
             deviceLockPollTimer_.stop(); //No need to check for unlock as no unpause anyway
         }
@@ -423,9 +423,22 @@ void SeaScene::handleScreenTapped()
         {
             pAboutBoxItem_->hide();
             pPausetextItem_->show();
+            return;
         }
     }
 
+    //If the game is paused, check if the level completed item is shown
+
+    if (pLevelCompletedItem_)
+    {
+        if (pLevelCompletedItem_->isVisible())
+        {
+            pLevelCompletedItem_->hide();
+            restartLevel(); //Current level has already been set to the next one before showing the level completed item
+            pPauseAction_->setChecked(false); //unpause
+            return;
+        }
+    }
   
     //If the game is paused, check if the victory item is being shown
     if(pVictoryCongratulationsItem_)
@@ -439,6 +452,7 @@ void SeaScene::handleScreenTapped()
         }
     }
 
+
     //If the game is paused and no victory, check if menu item was selected
 
     QList<QGraphicsItem *> items = selectedItems();
@@ -606,10 +620,18 @@ void SeaScene::about()
 
 void SeaScene::restartLevel()
 {
+
+    levelScore_ = 0;
+
     setupMap(levelset_.getLevel(currentLevel_));  //getLevel() returns default constructor Level if index is invalid, so no risk of crash
+
+    scoreCounter_.start();
+
     vibrationActivate(pVibrateAction_->isChecked());  //Vibration effects are lost without this
    // qDebug() << pVibrateAction_->isChecked();
     autopauseTimer.start();  //reset counting towards autopause
+
+
 }
 
 
@@ -618,11 +640,24 @@ void SeaScene::nextLevel()
 {
 
     //get score for previous level
-    int score = scoreCounter_.elapsed()/1000;
-    totalScore_ += score;
+    levelScore_ += scoreCounter_.elapsed();
+    totalScore_ += levelScore_;
     int highscore = levelset_.getLevelHighScore(currentLevel_);
+    qDebug() << highscore;
 
-    QString scoretext = tr("Your time: %1 min %2 s<br>Best time: %3 min %4 sec").arg(score/60).arg(score%60).arg(highscore/60).arg(highscore%60);
+    QString scoretext;
+
+    if (levelScore_ >= highscore)
+    {
+        scoretext = tr("<font size=\"5\" color = darkorange>Your time: %1.%2 s<br>Best time: %3.%4 s<br><br>Tap to start the next level").arg(levelScore_/1000).arg((levelScore_%1000)/100).arg(highscore/1000).arg((highscore%1000)/100);
+    }
+
+    else //New high score!
+
+    {
+        scoretext = tr("<font size=\"5\" color = darkorange>Your time %1.%2 s is the new best time!<br>br> Tap to start the next level").arg(levelScore_/1000).arg((levelScore_%1000)/100);
+        levelset_.setLevelHighScore(currentLevel_,levelScore_);
+    }
 
     //pause to show the highscore or victory screen