From 6f8e2c65991b2451bf8a54c7d82fc2a4d6aa63f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Tue, 14 Jun 2011 15:03:58 +0300 Subject: [PATCH] Victory dialog shown and game restarted when all ghosts found Does not support more than one level yet. --- mainwindow.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++-- mainwindow.h | 2 ++ orientationcontrol2pix.qrc | 1 + seascene.cpp | 2 +- seascene.h | 2 ++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 971bc1c..0153826 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include + #include @@ -18,9 +21,9 @@ MainWindow::MainWindow(QWidget *parent) setWindowIcon(QIcon(":/pix/laiva_10aave.png")); pScene_ = new SeaScene (); - pView_ = new QGraphicsView (); - + connect(pScene_,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel())); + pView_ = new QGraphicsView (); pView_->setScene(pScene_); setCentralWidget(pView_); @@ -74,7 +77,7 @@ void MainWindow::initializeBoundaries() qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height(); - pScene_->setupMap(11,5,5); + restartLevel(); } void MainWindow::pause(bool paused) @@ -115,3 +118,61 @@ void MainWindow::about() } + +void MainWindow::nextLevel() +{ + + //for now, just the handling of last level is implemented, and there is just one level + + qDebug() << "starting game over"; + QPixmap victoryIcon (":/pix/aavesaari.png"); +// QMessageBox victoryBox(QMessageBox::Information, tr("You won1"), tr("Congratulations! You have saved all the ghosts.")); + +// victoryBox.setIconPixmap(victoryIcon); +// victoryBox.addButton("Start a new game",QMessageBox::YesRole); +// victoryBox.addButton("Quit",QMessageBox::NoRole); + +// victoryBox.exec(); + + + QDialog* pVictoryDialog = new QDialog(this); + pVictoryDialog->setWindowTitle(tr("You won!")); + + + QPushButton* pPlayAgainButton = new QPushButton(tr("Play again")); + QPushButton* pQuitButton = new QPushButton(tr("Quit game")); + QLabel* pVictoryLabel = new QLabel(); + pVictoryLabel->setPixmap(victoryIcon); + QLabel* pTextLabel = new QLabel(tr("Congratulations!

You have saved all the ghosts.")); + + + QVBoxLayout* pMainLayout = new QVBoxLayout; + + QHBoxLayout* pTopLayout = new QHBoxLayout; + pMainLayout->addLayout(pTopLayout); + + pTopLayout->addWidget(pVictoryLabel); + pTopLayout->addWidget(pTextLabel); + + + + QHBoxLayout* pButtonLayout = new QHBoxLayout(); + pMainLayout->addLayout(pButtonLayout); + + + // pButtonLayout->addWidget(pQuitButton); + pButtonLayout->addWidget(pPlayAgainButton); + + + + pVictoryDialog->setLayout(pMainLayout); + + connect(pPlayAgainButton, SIGNAL(clicked()),pVictoryDialog,SLOT(accept())); + + pVictoryDialog->exec(); + + restartLevel(); + + + +} diff --git a/mainwindow.h b/mainwindow.h index 75f4779..2834154 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,8 @@ public slots: void pause(bool paused); void restartLevel(); void about(); + void nextLevel(); + private: diff --git a/orientationcontrol2pix.qrc b/orientationcontrol2pix.qrc index 8ac3974..e695634 100644 --- a/orientationcontrol2pix.qrc +++ b/orientationcontrol2pix.qrc @@ -15,5 +15,6 @@ laiva_8aave.png laiva_9aave.png laiva_10aave.png + aavesaari.png diff --git a/seascene.cpp b/seascene.cpp index 6787fc5..7a6a9db 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -239,7 +239,7 @@ void SeaScene::removeGhost(QGraphicsItem *pGhost) ghostsLeft_--; if (ghostsLeft_ == 0) { - //here whatever happens when a level is complete / a signal + emit allGhostsPicked(); qDebug() << "All ghosts picked!"; } } diff --git a/seascene.h b/seascene.h index 6795bf4..a296710 100644 --- a/seascene.h +++ b/seascene.h @@ -11,6 +11,8 @@ public: signals: + void allGhostsPicked(); + public slots: /*! Places all needed items for a level to (re)start. -- 1.7.9.5