#include <QApplication>
#include <QLabel>
#include <QPushButton>
- #include <QVBoxLayout>
+#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
- paused_ = false;
-
setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
+ setWindowTitle("Ghosts Overboard");
pScene_ = new SeaScene ();
connect(pScene_,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
QAction * pPauseAction = new QAction(tr("Pause"),this);
pPauseAction->setCheckable(true);
addAction(pPauseAction);
- connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
+ connect(pPauseAction,SIGNAL(triggered(bool)),pScene_,SLOT(pause(bool)));
menuBar()->addAction(pPauseAction);
QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
restartLevel();
}
-void MainWindow::pause(bool paused)
-{
-// qDebug() << "pause pressed " << paused;
- if (paused_ == paused)
- return;
-
- paused_ = paused;
-
- if (paused == false)
- {
- // qDebug() << "starting to move again";
- pTursas_->startMoving();
- }
-
- else
- {
- qDebug("about to stop movement");
- pTursas_->stopMoving();
- }
-
-}
void MainWindow::restartLevel()
{
- pScene_->setupMap(5,5,5);
+ pScene_->setupMap(5,10,0);
}
void MainWindow::about()
SeaScene::SeaScene(QObject *parent) :
QGraphicsScene(parent)
{
+ paused_ = false;
+
//set background
QPixmap waves (":/pix/meri.png");
addItem(pOctopus);
pOctopus->startMoving();
movingItems_.append(pOctopus);
+ connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving()));
+ connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving()));
delete pPosition;
}
connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
pShip->startMoving();
movingItems_.append(pShip);
+ connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
+ connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving()));
delete pPosition;
}
spreadGhosts(ghosts);
}
+
+void SeaScene::pause(bool paused)
+{
+ // qDebug() << "pause pressed " << paused;
+ if (paused_ == paused)
+ return;
+
+ paused_ = paused;
+
+ if (paused == false)
+ {
+ // qDebug() << "starting to move again";
+ emit pauseOff();
+ }
+
+ else
+ {
+ // qDebug("about to stop movement");
+ emit pauseOn();
+ }
+}
signals:
void allGhostsPicked();
+ void pauseOn();
+ void pauseOff();
public slots:
void ghostsDropped(int ghosts);
+ void pause (bool paused);
+
protected:
/*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
QList<QGraphicsItem*> movingItems_;
+ bool paused_;
+