Work towards highscore
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 12 Sep 2011 17:24:11 +0000 (20:24 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 12 Sep 2011 17:24:11 +0000 (20:24 +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.

Conflicts:

seascene.cpp
seascene.h

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 b1a7d75..27679db 100644 (file)
@@ -78,6 +78,8 @@ SeaScene::SeaScene(QObject *parent) :
 
     currentLevel_ = 0;
 
+    totalScore_ = 0;
+
     //This ensures that nextlevel will not be called until its safe to delete the Ship object.
     //Leaving out Qt::QueuedConnection or calling nextlevel directly instead of emitting the signal will CRASH
     connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()),Qt::QueuedConnection);
@@ -115,6 +117,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     createAboutBoxItems();
     createVictoryItems();
 
+    createLevelCompletedItem();
+
 
     //empty the list of moving items
 
@@ -233,6 +237,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     }
     delete pPosition;
 
+    scoreCounter_.start();
+
 
 }
 
@@ -601,26 +607,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();
-
     }
 }
 
@@ -628,6 +640,7 @@ void SeaScene::nextLevel()
 void SeaScene::restartGame()
 {
     currentLevel_ = 0;
+    totalScore_ = 0;
     restartLevel();
 }
 
@@ -706,9 +719,22 @@ void SeaScene::setItemPointersNull()
 //    pMinimizeItem_ = NULL; //Fremantle spesific
 
     pAboutBoxItem_ = NULL;
+    pLevelCompletedItem_ = NULL;
+
 }
 
 void SeaScene::turnPauseOn()
 {
     pPauseAction_->setChecked(true);
 }
+
+}
+
+void SeaScene::createLevelCompletedItem()
+{
+    pLevelCompletedItem_ = new QGraphicsTextItem;
+    addItem(pLevelCompletedItem_);
+    pLevelCompletedItem_->setPos(20,20);
+    pLevelCompletedItem_->setZValue(1000);
+    pLevelCompletedItem_->hide();
+    //The text is set at usetime
index 0748f3b..022b71d 100644 (file)
@@ -31,6 +31,7 @@
 #include "levelset.h"
 #include <QAction>
 #include <QTimer>
+#include <QTime>
 
 class SeaScene : public QGraphicsScene
 {
@@ -81,9 +82,6 @@ public slots:
 
     void softContinue();
 
-    void createAboutBoxItems();
-    void createVictoryItems();
-
     void setItemPointersNull();
 
     void turnPauseOn();
@@ -100,6 +98,9 @@ protected:
 
     void createMenuItems();
     void prepareForMenu(QGraphicsItem * pItem);
+    void createAboutBoxItems();
+    void createVictoryItems();
+    void createLevelCompletedItem();
 
     const QString ghostImageFilename_;
     const QString rockImageFilename_;
@@ -130,6 +131,8 @@ protected:
     QGraphicsTextItem * pAboutBoxItem_;
     QGraphicsTextItem * pVictoryCongratulationsItem_;
 
+    QGraphicsTextItem * pLevelCompletedItem_;
+
 
     Levelset levelset_;
 
@@ -144,6 +147,9 @@ protected:
 
     QTimer autopauseTimer;
 
+
+    QTime scoreCounter_;
+    int totalScore_;
 };
 
 #endif // SEASCENE_H