From: cboissie Date: Mon, 30 May 2011 23:55:45 +0000 (+0200) Subject: Dirty system to reload game when you lose/win. (at least it works and with no segfaul... X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=52399d5562aaa0161444cc80d480c233689979f0;p=Bug_Attack.git Dirty system to reload game when you lose/win. (at least it works and with no segfaults things... : P ) --- diff --git a/enemyfactory.cpp b/enemyfactory.cpp index fed6467..bc1fc1b 100644 --- a/enemyfactory.cpp +++ b/enemyfactory.cpp @@ -134,7 +134,7 @@ void EnemyFactory::launchWaves(void){ void EnemyFactory::produceWave(void){ _waveTimerStep+= 1; /* pas très sur de ça */ - if (_waveTimerStep < (GAME::FPS / 2)) // FIXME : ajuster la vitesse. + if (_waveTimerStep < (GAME::FPS / 2)) return; _waveTimerStep = 0; @@ -143,7 +143,7 @@ void EnemyFactory::produceWave(void){ if(_currentMap->getEnemyList().empty()) { // Fin de partie : Gagné ! - emit gameWon(QString("Vous avez gagné")); + emit gameWon(QString("Vous avez gagne !!")); } return; diff --git a/mainwindow.cpp b/mainwindow.cpp index d5a3fbb..fe80fe2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,10 +9,16 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); + // Lance le jeu automatiquement au démarrage de l'application + this->launchGame(parent); +} + +void MainWindow::launchGame(QWidget *parent) { + /** * Initialisation des données du joueur **/ - _player = new Player(999,10); // 22 - 10 + _player = new Player(22,10); // 22 - 10 /** @@ -29,14 +35,12 @@ MainWindow::MainWindow(QWidget *parent) : _view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); - _view->show(); - - /** * Interface graphique **/ /// Lancement de la prochaine vague // . Lance la production d'ennemi + ui->launchWaveButton->setDisabled(false); QObject::connect(ui->launchWaveButton, SIGNAL(pressed()),_sceneMap->getWaveGenerator(),SLOT(launchWaves())); // . Change le texte d'ambiance associé à la vague courante QObject::connect(_sceneMap->getWaveGenerator(),SIGNAL(changeWaveDescLabel(QString)),ui->waveDescLabel,SLOT(setText(QString))); @@ -95,6 +99,10 @@ MainWindow::MainWindow(QWidget *parent) : _view->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(_view,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showMapContextMenu(const QPoint&))); QObject::connect(ui->pauseButton,SIGNAL(clicked()), _sceneMap,SLOT(setPause(void))); + + + /* AFFICHAGE */ + _view->show(); } void MainWindow::showMapContextMenu(const QPoint& pos) { @@ -143,11 +151,11 @@ void MainWindow::endGame(QString msg) { // Relance une nouvelle partie if (msgBox.clickedButton() == (QAbstractButton *) restartButton) { - + this->reloadGame(); } // Quitte l'application else if (msgBox.clickedButton() == (QAbstractButton *) quitButton) { - this->close(); + this->close(); } @@ -157,3 +165,19 @@ MainWindow::~MainWindow(void) { delete ui; } + +void MainWindow::reloadGame(void) { + + + // Désactive la partie précédente + _player->disconnect(); + _sceneMap->getWaveGenerator()->disconnect(); + _sceneMap->disconnect(); + _view->disconnect(); + this->disconnect(); + + // Relance le jeu (nb: les éléments de l'ancienne partie seront automatiquement supprimés par l'appel au new) + this->launchGame(this->parentWidget()); + + +} diff --git a/mainwindow.h b/mainwindow.h index b745530..cebcfc2 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -30,6 +30,8 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void launchGame(QWidget *parent); + void reloadGame(void); public slots: void showMapContextMenu(const QPoint& pos); diff --git a/types.h b/types.h index b63f1b6..721eeb1 100644 --- a/types.h +++ b/types.h @@ -16,7 +16,7 @@ typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE, MUSICIE namespace GAME { -static const short FPS = 30; +static const short FPS = 60; }