Victory dialog shown and game restarted when all ghosts found
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 12:03:58 +0000 (15:03 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 12:03:58 +0000 (15:03 +0300)
Does not support more than one level yet.

mainwindow.cpp
mainwindow.h
orientationcontrol2pix.qrc
seascene.cpp
seascene.h

index 971bc1c..0153826 100644 (file)
@@ -7,6 +7,9 @@
 #include <QMenuBar>
 #include <QMessageBox>
 #include <QApplication>
+#include <QLabel>
+#include <QPushButton>
+ #include <QVBoxLayout>
 
 
 
@@ -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! <p>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();
+
+
+
+}
index 75f4779..2834154 100644 (file)
@@ -19,6 +19,8 @@ public slots:
     void pause(bool paused);
     void restartLevel();
     void about();
+    void nextLevel();
+
 
 private:
 
index 8ac3974..e695634 100644 (file)
@@ -15,5 +15,6 @@
         <file>laiva_8aave.png</file>
         <file>laiva_9aave.png</file>
         <file>laiva_10aave.png</file>
+        <file>aavesaari.png</file>
     </qresource>
 </RCC>
index 6787fc5..7a6a9db 100644 (file)
@@ -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!";
     }
 }
index 6795bf4..a296710 100644 (file)
@@ -11,6 +11,8 @@ public:
 
 signals:
 
+    void allGhostsPicked();
+
 public slots:
 
     /*! Places all needed items for a level to (re)start.