Work towards highscore
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 6 Sep 2011 17:25:42 +0000 (20:25 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 6 Sep 2011 17:25:42 +0000 (20:25 +0300)
Can show time used for level and what high score was before it.
No longer knows how to advance to the next level.
Does not update high score.

levelset.cpp
seascene.cpp
seascene.h

index 7491dfd..721c273 100644 (file)
@@ -63,7 +63,7 @@ int Levelset::getTotalHighScore()
 {
     QSettings settings;
     settings.beginGroup(name_);
-    return settings.value("TotalHighScore",54000*10).toInt();
+    return settings.value("TotalHighScore",900*100).toInt();
 }
 
 void Levelset::setTotalHighScore(int highscore)
@@ -81,7 +81,7 @@ int Levelset::getLevelHighScore(int index)
     QString group = name_.append("/LevelHighScore");
     settings.beginGroup(group);
 
-    return settings.value(QString(index),54000).toInt();
+    return settings.value(QString(index),900).toInt();
 }
 
 void Levelset::setLevelHighScore(int index, int highScore)
index 63b22a0..ee4c334 100644 (file)
@@ -78,6 +78,8 @@ SeaScene::SeaScene(QObject *parent) :
 
     currentLevel_ = 0;
 
+    totalScore_ = 0;
+
 
     connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
 
@@ -120,6 +122,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
 
     createVictoryItems();
 
+    createLevelCompletedItem();
+
 
     //empty the list of moving items
 
@@ -238,6 +242,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     }
     delete pPosition;
 
+    scoreCounter_.start();
+
 
 }
 
@@ -611,26 +617,32 @@ void SeaScene::restartLevel()
 void SeaScene::nextLevel()
 {
 
-    currentLevel_++;
+    //get score for previous level
+    int score = scoreCounter_.elapsed()/1000;
+    totalScore_ += score;
+    int highscore = levelset_.getLevelHighScore(currentLevel_);
+
+    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);
 
-    if (!levelset_.isValid())
-        setupMap(Level());
+    //pause to show the highscore or victory screen
 
+    turnPauseOn();
+    pPausetextItem_->hide();
+
+
+    //Go to the next level if available
+    currentLevel_++;
 
     if ( currentLevel_ < levelset_.numberOfLevels() )
     {
-       restartLevel();
+       pLevelCompletedItem_->setHtml(scoretext);
+       pLevelCompletedItem_->show();
+//       restartLevel();
     }
 
     else //Victory!
     {
-
-        pPauseAction_->setChecked(true); //Pause the game while showing the victory dialog
-
-        pPausetextItem_->hide();
-
         pVictoryCongratulationsItem_->show();
-
     }
 }
 
@@ -638,6 +650,7 @@ void SeaScene::nextLevel()
 void SeaScene::restartGame()
 {
     currentLevel_ = 0;
+    totalScore_ = 0;
     restartLevel();
 }
 
@@ -716,6 +729,8 @@ void SeaScene::setItemPointersNull()
 
     pAboutBoxItem_ = NULL;
     pVictoryCongratulationsItem_ = NULL;
+    pLevelCompletedItem_ = NULL;
+
 
 }
 
@@ -752,3 +767,14 @@ void SeaScene::pollDeviceLocked()
         }
     }
 }
+
+void SeaScene::createLevelCompletedItem()
+{
+    pLevelCompletedItem_ = new QGraphicsTextItem;
+    addItem(pLevelCompletedItem_);
+    pLevelCompletedItem_->setPos(20,20);
+    pLevelCompletedItem_->setZValue(1000);
+    pLevelCompletedItem_->hide();
+    //The text is set at usetime
+
+}
index e246575..c5fe8f8 100644 (file)
@@ -32,6 +32,7 @@
 #include <QAction>
 #include <QTimer>
 #include <QSystemDeviceInfo>
+#include <QTime>
 
 using namespace QtMobility;
 
@@ -87,10 +88,6 @@ public slots:
 
     void softContinue();
 
-    void createAboutBoxItems();
-
-    void createVictoryItems();
-
     void setItemPointersNull();
 
     void turnPauseOn();
@@ -111,6 +108,9 @@ protected:
 
     void createMenuItems();
     void prepareForMenu(QGraphicsItem * pItem);
+    void createAboutBoxItems();
+    void createVictoryItems();
+    void createLevelCompletedItem();
 
     const QString ghostImageFilename_;
     const QString rockImageFilename_;
@@ -141,6 +141,8 @@ protected:
     QGraphicsTextItem * pVictoryCongratulationsItem_;
     QGraphicsTextItem * pAboutBoxItem_;
 
+    QGraphicsTextItem * pLevelCompletedItem_;
+
 
     Levelset levelset_;
 
@@ -159,6 +161,9 @@ protected:
 
     QTimer deviceLockPollTimer_;
 
+    QTime scoreCounter_;
+    int totalScore_;
+
 };
 
 #endif // SEASCENE_H