currentLevel_ = 0;
+ totalScore_ = 0;
+
connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
createVictoryItems();
+ createLevelCompletedItem();
+
//empty the list of moving items
}
delete pPosition;
+ scoreCounter_.start();
+
}
{
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_)
}
}
+
//If the game is paused and no victory, check if menu item was selected
QList<QGraphicsItem *> items = selectedItems();
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();
-
}
}
void SeaScene::restartGame()
{
currentLevel_ = 0;
+ totalScore_ = 0;
restartLevel();
}
pAboutBoxItem_ = NULL;
pVictoryCongratulationsItem_ = NULL;
+ pLevelCompletedItem_ = NULL;
+
}
}
}
}
+
+void SeaScene::createLevelCompletedItem()
+{
+ pLevelCompletedItem_ = new QGraphicsTextItem;
+ addItem(pLevelCompletedItem_);
+ pLevelCompletedItem_->setPos(20,20);
+ pLevelCompletedItem_->setZValue(1000);
+ pLevelCompletedItem_->hide();
+ //The text is set at usetime
+
+}