]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
Dirty system to reload game when you lose/win. (at least it works and with no segfaul...
authorcboissie <clemzbox@gmail.com>
Mon, 30 May 2011 23:55:45 +0000 (01:55 +0200)
committercboissie <clemzbox@gmail.com>
Mon, 30 May 2011 23:55:45 +0000 (01:55 +0200)
enemyfactory.cpp
mainwindow.cpp
mainwindow.h
types.h

index fed6467ff21921200dd918363f6536db928a0e3d..bc1fc1b7c237db8302e9e1d635970a5d837c6aa1 100644 (file)
@@ -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;
index d5a3fbb255f842b7902f73baaa3e4a8f4479b777..fe80fe24b7f2fc53031ae7b9d43ec634310d958e 100644 (file)
@@ -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());
+
+
+}
index b7455304f14a8ccb52e4ebb94b409ed2f0e0844b..cebcfc202dcb761a1e883672413e9e6b52922d16 100644 (file)
@@ -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 b63f1b6f5da8b412712ffa0cbf4b2492592d0547..721eeb166b1511e5813b247c962fa13ac2c003b3 100644 (file)
--- 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;
 
 }