]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
The musician is now available !
authorcboissie <clemzbox@gmail.com>
Mon, 30 May 2011 23:15:42 +0000 (01:15 +0200)
committercboissie <clemzbox@gmail.com>
Mon, 30 May 2011 23:15:42 +0000 (01:15 +0200)
(NB: notices that the bonus is a percent, so "int*percent" -> "int" !

14 files changed:
defenser.cpp
defenser.h
enemy.cpp
enemyfactory.cpp
enemyfactory.h
mainwindow.cpp
mainwindow.h
mainwindow.ui
map.cpp
map.h
player.cpp
player.h
tile.h
types.h

index 691d5f86fa648e165b22d13b8a1f83c2845640a5..7ffb77e17db4da4f78e9053e307d7d3cff9e2650 100644 (file)
@@ -13,6 +13,7 @@ Defenser::Defenser(int posx,int posy,int level,Map* map)
     this->setIsSelected(true); // Appel à la méthode pour rafraichir l'affichage
     // Met le compteur interne à 0 et relie le FPS au tir
     _shootTimerStep = 0;
+    _powerBonus = 1;
     // QObject::connect(&map->gameTimer,SIGNAL(timeout()), this,SLOT(shootTarget()));
 }
 
@@ -24,6 +25,7 @@ void Defenser::setIsSelected(bool selected) {
 
 int Defenser::getLevel(void) const { return _level; }
 bool Defenser::isSelected(void) const { return _isSelected; }
+void Defenser::shootTarget(void) {}
 
 void Defenser::increaseLevel(void) {
     if(_level < 3) _level++;
@@ -73,6 +75,29 @@ QRectF Defenser::boundingRect(void) const {
     return QRectF(-32,-32,_range,_range);
 }
 
+void Defenser::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*) {
+    // Si la tourelle est selectionnée...
+    if(_isSelected) {
+
+        painter->save();
+
+        // Dessine la portée de la tourelle
+        painter->setOpacity(0.2f);
+
+            // Si on a un bonus, la portée est dessinée en dorée
+            if(_powerBonus > 1)
+                painter->setBrush(QBrush(Qt::yellow,Qt::SolidPattern));
+            // Sinon on l'affiche en blanc
+            else
+                painter->setBrush(QBrush(Qt::white,Qt::SolidPattern));
+
+        painter->drawEllipse((-_range/32)*16,(-_range/32)*16,_range+32,_range+32);
+
+        painter->restore();
+    }
+}
+
+
 void Defenser::setTarget(float targetX,float targetY) {
     // Sauvegarde la position de la cible courante
     _targetX = targetX;
@@ -108,6 +133,25 @@ bool Defenser::isShooting(void) const { return _isShooting;}
 // Cette méthode est néanmoins virtuelle pour cas particulier(s)
 bool Defenser::isLevelMax(void) const { return _level==3; }
 
+
+void Defenser::setBonus(float powerBonus) {
+
+    std::cout << "On vient de me mettre un bonus de " << powerBonus << std::endl;
+
+    // Applique un bonus de puissance de tir à la tourelle
+    // Si un bonus existe déjà, le bonus le plus fort est gardé
+    if(_powerBonus > powerBonus)
+        return;
+    _powerBonus = powerBonus;
+
+}
+void Defenser::removeBonus(void) {
+
+    std::cout << "J'ai perdu mon bonus de " << _powerBonus << std::endl;
+
+    _powerBonus = 1;
+}
+
 /**
 * PISTOLET A EAU
 **/
@@ -160,21 +204,15 @@ void WaterGun::updateStats(void) {
 }
 
 
-void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) {
+void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w) {
 
-    // Si la tourelle est selectionnée, on dessine un halo autour
-    if(_isSelected) {
-        painter->setBrush(QBrush(Qt::yellow));
-        painter->drawRect(-2,-2,36,36);
-    }
+    // Dessine la portée de la tourelle si celle ci est selectionnée
+    Defenser::paint(painter,so,w);
 
     // Dessine la tourelle
     painter->setBrush(QBrush(Qt::blue));
     painter->drawRect(0,0,32,32);
 
-    // Dessine la portée de la tourelle
-    painter->setBrush(QBrush(Qt::blue,Qt::NoBrush));
-    painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range);
 }
 
 void WaterGun::shootTarget(void) {
@@ -189,7 +227,7 @@ void WaterGun::shootTarget(void) {
     _shootTimerStep = 0;
 
     // Créé un nouveau projectile au niveau du centre de la tourelle
-    Projectile* shot = new ProjectileWater(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map);
+    Projectile* shot = new ProjectileWater(this->x()+14,this->y()+14,_targetX,_targetY,_power*_powerBonus, _map);
     _map->addItem(shot);
 
 }
@@ -250,21 +288,14 @@ void Slingshot::updateStats(void) {
 
 
 
-void Slingshot::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) {
+void Slingshot::paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w) {
 
-    // Si la tourelle est selectionnée, on dessine un halo autour
-    if(_isSelected) {
-        painter->setBrush(QBrush(Qt::yellow));
-        painter->drawRect(-2,-2,36,36);
-    }
+    // Dessine la portée de la tourelle si celle ci est selectionnée
+    Defenser::paint(painter,so,w);
 
     // Dessine la tourelle
     painter->setBrush(QBrush(Qt::gray));
     painter->drawRect(0,0,32,32);
-
-    // Dessine la portée de la tourelle
-    painter->setBrush(QBrush(Qt::blue,Qt::NoBrush));
-    painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range);
 }
 
 void Slingshot::shootTarget(void) {
@@ -279,7 +310,7 @@ void Slingshot::shootTarget(void) {
     _shootTimerStep = 0;
 
     // Créé un nouveau projectile au niveau du centre de la tourelle
-    Projectile* shot = new ProjectileStone(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map);
+    Projectile* shot = new ProjectileStone(this->x()+14,this->y()+14,_targetX,_targetY,_power*_powerBonus, _map);
     _map->addItem(shot);
 
 }
@@ -340,21 +371,16 @@ void Paintball::updateStats(void) {
 
 
 
-void Paintball::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) {
+void Paintball::paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w) {
 
-    // Si la tourelle est selectionnée, on dessine un halo autour
-    if(_isSelected) {
-        painter->setBrush(QBrush(Qt::yellow));
-        painter->drawRect(-2,-2,36,36);
-    }
+    // Dessine la portée de la tourelle si celle ci est selectionnée
+    Defenser::paint(painter,so,w);
 
     // Dessine la tourelle
     painter->setBrush(QBrush(Qt::white));
     painter->drawRect(0,0,32,32);
 
-    // Dessine la portée de la tourelle
-    painter->setBrush(QBrush(Qt::blue,Qt::NoBrush));
-    painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range);
+
 }
 
 void Paintball::shootTarget(void) {
@@ -369,7 +395,7 @@ void Paintball::shootTarget(void) {
     _shootTimerStep = 0;
 
     // Créé un nouveau projectile au niveau du centre de la tourelle
-    Projectile* shot = new ProjectilePaintball(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map);
+    Projectile* shot = new ProjectilePaintball(this->x()+14,this->y()+14,_targetX,_targetY,_power*_powerBonus, _map);
     _map->addItem(shot);
 
 }
@@ -377,7 +403,7 @@ void Paintball::shootTarget(void) {
 
 
 /**
-* PAINTBALL
+* PETANQUE
 **/
 
 Bowling::Bowling(int posx,int posy,int level,Map* map)
@@ -431,21 +457,15 @@ void Bowling::updateStats(void) {
 
 
 
-void Bowling::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) {
+void Bowling::paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w) {
 
-    // Si la tourelle est selectionnée, on dessine un halo autour
-    if(_isSelected) {
-        painter->setBrush(QBrush(Qt::yellow));
-        painter->drawRect(-2,-2,36,36);
-    }
+    // Dessine la portée de la tourelle si celle ci est selectionnée
+    Defenser::paint(painter,so,w);
 
     // Dessine la tourelle
     painter->setBrush(QBrush(Qt::black));
     painter->drawRect(0,0,32,32);
 
-    // Dessine la portée de la tourelle
-    painter->setBrush(QBrush(Qt::blue,Qt::NoBrush));
-    painter->drawEllipse((-_range/32)*16+16,(-_range/32)*16+16,_range,_range);
 }
 
 void Bowling::shootTarget(void) {
@@ -460,12 +480,137 @@ void Bowling::shootTarget(void) {
     _shootTimerStep = 0;
 
     // Créé un nouveau projectile au niveau du centre de la tourelle
-    Projectile* shot = new ProjectileBowling(this->x()+14,this->y()+14,_targetX,_targetY,_power, _map);
+    Projectile* shot = new ProjectileBowling(this->x()+14,this->y()+14,_targetX,_targetY,_power*_powerBonus, _map);
     _map->addItem(shot);
 
 }
 
+/**
+* MUSICIEN
+**/
+
+Musician::Musician(int posx,int posy,int level,Map* map)
+    : Defenser(posx,posy,level,map)
+{
+    // Caractéristiques
+    _range = 1; // portée de 1 case
+    this->updateStats();
+
+    // Mise à jour auto des bonus
+    QObject::connect(_map,SIGNAL(updateBonuses()),this,SLOT(applyBonuses()));
+}
+
+int Musician::getCost(int level) const{
+
+    // Si aucune valeur en argument, alors on affiche le coût du niveau courant
+    if(level == -1) level = _level;
 
+    switch(level) {
+        case 1: return BASIC_COST;
+        case 2: return INTERMEDIATE_COST;
+        default: return HIGHEST_COST;
+    }
+}
+
+QString Musician::getInfos(void) const {
+
+    // Infos générales
+    QString infos = "Musicien de niveau ";
+    infos+= QString::number(_level);
+    // Amélioration
+    if(!this->isLevelMax()) {
+        infos+= "\n- Amelioration : ";
+        infos+= QString::number(this->getCost(_level+1));
+    }
+    // Revente
+    infos+= "\n- Revente : ";
+    infos+= QString::number(this->getCost(_level)/2);
+
+    return infos;
+}
+
+
+
+void Musician::updateStats(void) {
+    _powerBonus = 1+_level*0.2f; // Pourcentage de bonus (>1)
+}
+
+
+
+void Musician::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*) {
+
+    // Si la tourelle est selectionnée...
+    if(_isSelected) {
+
+        painter->save();
+
+        // Dessine la portée de la tourelle
+        painter->setOpacity(0.2f);
+        painter->setBrush(QBrush(Qt::yellow,Qt::SolidPattern));
+        painter->drawRect(-16*2,-16*2,32*_range*3,32*_range*3);
+
+        painter->restore();
+    }
+
+    // Dessine la tourelle
+    painter->setBrush(QBrush(Qt::yellow));
+    painter->drawRect(0,0,32,32);
+
+}
+
+void Musician::advance(int){}
+
+float Musician::getPowerBonus(void) const { return _powerBonus; }
+
+
+// Les méthodes suivantes peuvent être appellée de manière générale via
+// un signal ou de manière indépendante lors de l'ajout/suppression d'une tourelle
+
+void Musician::applyBonuses(void) {
+
+    Defenser* bonusTarget;
+
+    for(int i = -_range ; i <= _range ; ++i) {
+
+        for(int j = -_range ; j <= _range ; ++j ) {
+
+            // Cas particulier où l'on est au centre (== Musicien lui même)
+            if(i==0 && j==0)
+                continue;
+
+            // On applique un bonus à l'éventuelle tourelle voisine
+            // NB: si le bonus appliqué est inférieur à un autre bonus, seul le bonus le plus fort sera conservé
+            if((bonusTarget = _map->getTurretAt(this->x()+32*i,this->y()+32*j)) != NULL) {
+                bonusTarget->setBonus(_powerBonus);
+                std::cout << "x:" << i << "y:" << j << std::endl;
+            }
+
+        } //eof
+    }// eof
+
+}
+
+
+// NB : l'appel à cette méthode doit être suivi d'un appel global à applyBonus
+void Musician::removeBonuses(void) {
+
+    Defenser* bonusTarget;
+
+    for(int i = -_range ; i <= _range ; ++i) {
+
+        for(int j = -_range ; j <= _range ; ++j ) {
+
+            // Cas particulier où l'on est au centre (== Musicien lui même)
+            if(i==0 && j==0)
+                continue;
+
+            // Bonus remis à la valeur initiale
+            if((bonusTarget = _map->getTurretAt(this->x()+32*i,this->y()+32*j)) != NULL && dynamic_cast<Musician*>(bonusTarget) == 0)
+                bonusTarget->removeBonus();
+        } //eof
+    }// eof
+
+}
 
 
 
index cc7041ca594794db7d3320af506c8b29242d6640..3de02fd37b6c61fc49e74d8e1dc2ae01e9b244b9 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef DEFENSER_H
 #define DEFENSER_H
 
+#include <QList>
 #include "map.h"
 #include "entity.h"
 
@@ -25,12 +26,16 @@ public:
     void setIsShooting(bool state);
     void setTarget(float targetX,float targetY);
     QRectF boundingRect(void) const;
+    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
     bool isShooting(void) const;
+    void setBonus(float powerUp);
+    void removeBonus(void);
+
 
 protected:
     virtual void updateStats(void) = 0;
     virtual void advance(int phase);
-    virtual void shootTarget(void) = 0;
+    virtual void shootTarget(void);
 
     int _shootTimerStep;
     int _level;
@@ -38,6 +43,7 @@ protected:
     float _rate;
     float _range;
     int _power;
+    float _powerBonus;
     float _targetX;
     float _targetY;
     Map* _map;
@@ -73,7 +79,7 @@ public:
     WaterGun(int posx,int posy,int level,Map* map);
     int getCost(int level = -1) const;
     QString getInfos(void) const;   
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*);
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
     static int getBasicCost(void) { return BASIC_COST; }
 
 
@@ -103,7 +109,7 @@ public:
     Slingshot(int posx,int posy,int level,Map* map);
     int getCost(int level = -1) const;
     QString getInfos(void) const;
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*);
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
     static int getBasicCost(void) { return BASIC_COST; }
 
 protected:
@@ -131,7 +137,7 @@ public:
     Paintball(int posx,int posy,int level,Map* map);
     int getCost(int level = -1) const;
     QString getInfos(void) const;
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*);
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
     static int getBasicCost(void) { return BASIC_COST; }
 
 protected:
@@ -159,10 +165,44 @@ public:
     Bowling(int posx,int posy,int level,Map* map);
     int getCost(int level = -1) const;
     QString getInfos(void) const;
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*);
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
     static int getBasicCost(void) { return BASIC_COST; }
 
 protected:
     void updateStats(void);
 };
+
+/**
+* MUSICIEN
+**/
+
+
+class Musician : public Defenser
+{
+    Q_OBJECT
+
+public:
+
+    static const int BASIC_COST = 15;
+    static const int INTERMEDIATE_COST = 40;
+    static const int HIGHEST_COST = 80;
+
+    Musician(int posx,int posy,int level,Map* map);
+    int getCost(int level = -1) const;
+    QString getInfos(void) const;
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *so, QWidget *w);
+    static int getBasicCost(void) { return BASIC_COST; }
+
+    float getPowerBonus(void) const;
+
+protected:
+    void advance(int phase); // Masquage de méthode
+    void updateStats(void);
+
+public slots:
+    void applyBonuses(void);
+    void removeBonuses(void);
+
+};
+
 #endif // DEFENSER_H
index 143c474f4dacfc3114a13cc01847c399048123ca..d3d7fc0f5223447ca93bbc551cc0cfcb8b17d9fd 100644 (file)
--- a/enemy.cpp
+++ b/enemy.cpp
@@ -202,6 +202,7 @@ Fourmi::Fourmi(Map* map,int posx,int posy, float size):Enemy(map,posx,posy,size)
     _hpMax = _hp;
     _resistance = size*size;
     _speed = 2 + size/2;
+    _speedUp = false; // Par défaut on désactive la course
 
     // Images et animations
     for(int i = 0; i < 3; ++i) {
@@ -322,6 +323,7 @@ Moustique::Moustique(Map* map,int posx,int posy, float size):Enemy(map,posx,posy
     _type = DEFAULT_TYPE;
     _hp = 6*size*size;
     _hpMax = _hp;
+    _stateCounter = 0; // Initialise la machine à état
 
     this->updateStats();
 
index 4d751c48dcd7aa27857b686c903c27e1ebb789f5..fed6467ff21921200dd918363f6536db928a0e3d 100644 (file)
@@ -142,22 +142,8 @@ void EnemyFactory::produceWave(void){
     if(_mapWaves.empty()){
         if(_currentMap->getEnemyList().empty()) {
 
-            //!-- BLOC DE FIN DE PARTIE : Victoire
-            QMessageBox msgBox;
-            msgBox.setText("Fin de partie");
-            msgBox.setInformativeText("Vous avez gagné.");
-
-            QPushButton *restartButton = msgBox.addButton(tr("Rejouer"), QMessageBox::ActionRole);
-            QPushButton *quitButton = msgBox.addButton(tr("Quitter"), QMessageBox::ActionRole);
-            msgBox.exec();
-
-            if (msgBox.clickedButton() == (QAbstractButton *) restartButton) {
-
-            } else if (msgBox.clickedButton() == (QAbstractButton *) quitButton) {
-                 exit(0);
-            }
-            // FIN DU BLOC  --!
-
+            // Fin de partie : Gagné !
+            emit gameWon(QString("Vous avez gagné"));
 
         }
         return;
index fabe4ccf884eadbd0b9058d8e396397bc4f91a8d..57fcc71abd636d49d423b75aa9b2e26f84d1c5e7 100644 (file)
@@ -61,8 +61,9 @@ public slots:
     void produceWave(void);
 
 signals:
-    void changeWaveDescLabel(QString text);
-    void setLaunchWaveButtonEnabled(bool state);
+    void changeWaveDescLabel(QString);
+    void setLaunchWaveButtonEnabled(bool);
+    void gameWon(QString);
 
 };
 
index 08f99e3e56eaae52f7b945189731e9365b055823..d5a3fbb255f842b7902f73baaa3e4a8f4479b777 100644 (file)
@@ -12,7 +12,8 @@ MainWindow::MainWindow(QWidget *parent) :
     /**
     * Initialisation des données du joueur
     **/
-    _player = new Player(22,10);
+    _player = new Player(999,10); // 22 - 10
+
 
     /**
     * Création et chargement de la map
@@ -25,7 +26,7 @@ MainWindow::MainWindow(QWidget *parent) :
     _view->setScene(_sceneMap);
     _view->setRenderHint(QPainter::Antialiasing);
     _view->setCacheMode(QGraphicsView::CacheBackground);
-    _view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+    _view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
 
 
     _view->show();
@@ -57,6 +58,9 @@ MainWindow::MainWindow(QWidget *parent) :
     // . Pétanque
     QObject::connect(ui->turretButton_Petanque,SIGNAL(pressed()),_player,SLOT(setTurretChoice4()));
     QObject::connect(_player,SIGNAL(setTurret4ButtonDisabled(bool)),ui->turretButton_Petanque,SLOT(setDisabled(bool)));
+    // . Musicien
+    QObject::connect(ui->turretButton_Musicien,SIGNAL(pressed()),_player,SLOT(setTurretChoice5()));
+    QObject::connect(_player,SIGNAL(setTurret5ButtonDisabled(bool)),ui->turretButton_Musicien,SLOT(setDisabled(bool)));
 
     // Demande d'informations sur une tourelle
     QObject::connect(_sceneMap,SIGNAL(turretInfosRequest(QString)),ui->turretInfoLabel,SLOT(setText(QString)));
@@ -80,6 +84,10 @@ MainWindow::MainWindow(QWidget *parent) :
     ui->livesCounter->display(_player->getLives());
     QObject::connect(_player,SIGNAL(livesValueChanged(int)),ui->livesCounter,SLOT(display(int)));
 
+    // Gameover
+    QObject::connect(_player,SIGNAL(gameLost(QString)),this,SLOT(endGame(QString)));
+    QObject::connect(_sceneMap->getWaveGenerator(),SIGNAL(gameWon(QString)),this,SLOT(endGame(QString)));
+
     /**
     * Divers
     **/
@@ -102,7 +110,7 @@ void MainWindow::showMapContextMenu(const QPoint& pos) {
    QAction* createTurret2 = myMenu.addAction("Lance-pierres");
    QAction* createTurret3 = myMenu.addAction("Paintball");
    QAction* createTurret4 = myMenu.addAction("Petanque");
-   myMenu.addAction("-- turret 5 --");
+   QAction* createTurret5 = myMenu.addAction("Musicien");
 
    // On regarde si un choix a été effectué et si la case est libre pour la pose d'une tourelle
    QAction* selectedItem = myMenu.exec(globalPos);
@@ -117,11 +125,35 @@ void MainWindow::showMapContextMenu(const QPoint& pos) {
            _sceneMap->addTurretAt(TYPE::PAINTBALL,mousePos.x(),mousePos.y());
        else if(selectedItem == createTurret4)
            _sceneMap->addTurretAt(TYPE::PETANQUE,mousePos.x(),mousePos.y());
+       else if(selectedItem == createTurret5)
+           _sceneMap->addTurretAt(TYPE::MUSICIEN,mousePos.x(),mousePos.y());
    }
 
 }
 
-MainWindow::~MainWindow()
+void MainWindow::endGame(QString msg) {
+
+    QMessageBox msgBox;
+    msgBox.setText("Fin de partie");
+    msgBox.setInformativeText(msg);
+
+    QPushButton *restartButton = msgBox.addButton(tr("Rejouer"), QMessageBox::ActionRole);
+    QPushButton *quitButton = msgBox.addButton(tr("Quitter"), QMessageBox::ActionRole);
+    msgBox.exec();
+
+    // Relance une nouvelle partie
+    if (msgBox.clickedButton() == (QAbstractButton *) restartButton) {
+
+    }
+    // Quitte l'application
+    else if (msgBox.clickedButton() == (QAbstractButton *) quitButton) {
+         this->close();
+    }
+
+
+}
+
+MainWindow::~MainWindow(void)
 {
     delete ui;
 }
index 69abdae5a9947247daf875229a47d89c95733ebc..b7455304f14a8ccb52e4ebb94b409ed2f0e0844b 100644 (file)
@@ -33,6 +33,7 @@ public:
 
 public slots:
     void showMapContextMenu(const QPoint& pos);
+    void endGame(QString msg);
 
 };
 
index f6fe65232c01b0a16bf071936cfb2b97d5f9ac00..14df2ac608049c40681307d512b2d49fe149eff5 100644 (file)
      <height>600</height>
     </size>
    </property>
-   <widget class="QWidget" name="verticalLayoutWidget">
-    <property name="geometry">
-     <rect>
-      <x>530</x>
-      <y>10</y>
-      <width>261</width>
-      <height>581</height>
-     </rect>
-    </property>
-    <layout class="QVBoxLayout" name="verticalLayout">
-     <item>
-      <widget class="QLabel" name="waveDescLabel">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="minimumSize">
-        <size>
-         <width>0</width>
-         <height>10</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>16777215</width>
-         <height>20</height>
-        </size>
-       </property>
-       <property name="text">
-        <string>Clique sur le bouton pour commencer.</string>
-       </property>
-       <property name="alignment">
-        <set>Qt::AlignCenter</set>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="launchWaveButton">
-       <property name="text">
-        <string>Lancer la vague !</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout_2">
-       <item>
-        <widget class="QLabel" name="creditLabel">
-         <property name="text">
-          <string>Bilou$e</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLCDNumber" name="creditCounter"/>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout_3">
-       <item>
-        <widget class="QLabel" name="livesLabel">
-         <property name="text">
-          <string>Vies</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLCDNumber" name="livesCounter"/>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <widget class="QGroupBox" name="groupBox">
-       <property name="title">
-        <string>Défenses</string>
-       </property>
-       <widget class="QPushButton" name="turretButton_PistoletAEau">
-        <property name="geometry">
-         <rect>
-          <x>20</x>
-          <y>30</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Pistolet à eau</string>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="turretButton_LancePierres">
-        <property name="geometry">
-         <rect>
-          <x>130</x>
-          <y>30</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Lance-pierres</string>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="turretButton_Paintball">
-        <property name="geometry">
-         <rect>
-          <x>20</x>
-          <y>60</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>PaintBall</string>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="turretButton_Petanque">
-        <property name="geometry">
-         <rect>
-          <x>130</x>
-          <y>60</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Pétanque</string>
-        </property>
-       </widget>
-      </widget>
-     </item>
-     <item>
-      <widget class="QGroupBox" name="groupBox_2">
-       <property name="enabled">
-        <bool>true</bool>
-       </property>
-       <property name="title">
-        <string>Informations</string>
-       </property>
-       <property name="flat">
-        <bool>false</bool>
-       </property>
-       <widget class="QLabel" name="turretInfoLabel">
-        <property name="geometry">
-         <rect>
-          <x>10</x>
-          <y>20</y>
-          <width>241</width>
-          <height>81</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Cliquez sur une tourelle pour avoir des informations, l'améliorer ou la revendre.</string>
-        </property>
-        <property name="textFormat">
-         <enum>Qt::AutoText</enum>
-        </property>
-        <property name="scaledContents">
-         <bool>false</bool>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignJustify|Qt::AlignTop</set>
-        </property>
-        <property name="wordWrap">
-         <bool>true</bool>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="upgradeTurretButton">
-        <property name="geometry">
-         <rect>
-          <x>20</x>
-          <y>100</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Améliorer</string>
-        </property>
-       </widget>
-       <widget class="QPushButton" name="sellTurretButton">
-        <property name="geometry">
-         <rect>
-          <x>140</x>
-          <y>100</y>
-          <width>98</width>
-          <height>27</height>
-         </rect>
-        </property>
-        <property name="text">
-         <string>Revendre</string>
-        </property>
-       </widget>
-      </widget>
-     </item>
-    </layout>
-   </widget>
    <widget class="QGraphicsView" name="graphicsView">
     <property name="geometry">
      <rect>
    <widget class="QPushButton" name="pauseButton">
     <property name="geometry">
      <rect>
-      <x>50</x>
-      <y>560</y>
-      <width>80</width>
+      <x>670</x>
+      <y>60</y>
+      <width>121</width>
       <height>26</height>
      </rect>
     </property>
      <string>Pause</string>
     </property>
    </widget>
+   <widget class="QLabel" name="waveDescLabel">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>10</y>
+      <width>261</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Clique sur le bouton pour commencer.</string>
+    </property>
+    <property name="scaledContents">
+     <bool>false</bool>
+    </property>
+    <property name="alignment">
+     <set>Qt::AlignHCenter|Qt::AlignTop</set>
+    </property>
+    <property name="wordWrap">
+     <bool>true</bool>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="launchWaveButton">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>60</y>
+      <width>129</width>
+      <height>27</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Lancer la vague !</string>
+    </property>
+   </widget>
+   <widget class="QWidget" name="">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>100</y>
+      <width>261</width>
+      <height>81</height>
+     </rect>
+    </property>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QLabel" name="creditLabel">
+       <property name="text">
+        <string>Bilou$e</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLCDNumber" name="creditCounter"/>
+     </item>
+    </layout>
+   </widget>
+   <widget class="QWidget" name="">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>190</y>
+      <width>261</width>
+      <height>81</height>
+     </rect>
+    </property>
+    <layout class="QHBoxLayout" name="horizontalLayout_3">
+     <item>
+      <widget class="QLabel" name="livesLabel">
+       <property name="text">
+        <string>Vies</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLCDNumber" name="livesCounter"/>
+     </item>
+    </layout>
+   </widget>
+   <widget class="QGroupBox" name="groupBox">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>280</y>
+      <width>259</width>
+      <height>126</height>
+     </rect>
+    </property>
+    <property name="title">
+     <string>Défenses</string>
+    </property>
+    <widget class="QPushButton" name="turretButton_PistoletAEau">
+     <property name="geometry">
+      <rect>
+       <x>30</x>
+       <y>30</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Pistolet à eau</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="turretButton_LancePierres">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>30</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Lance-pierres</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="turretButton_Paintball">
+     <property name="geometry">
+      <rect>
+       <x>30</x>
+       <y>60</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>PaintBall</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="turretButton_Petanque">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>60</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Pétanque</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="turretButton_Musicien">
+     <property name="geometry">
+      <rect>
+       <x>80</x>
+       <y>90</y>
+       <width>101</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Musicien</string>
+     </property>
+    </widget>
+   </widget>
+   <widget class="QGroupBox" name="groupBox_2">
+    <property name="enabled">
+     <bool>true</bool>
+    </property>
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>400</y>
+      <width>259</width>
+      <height>191</height>
+     </rect>
+    </property>
+    <property name="title">
+     <string>Informations</string>
+    </property>
+    <property name="flat">
+     <bool>false</bool>
+    </property>
+    <widget class="QLabel" name="turretInfoLabel">
+     <property name="geometry">
+      <rect>
+       <x>10</x>
+       <y>20</y>
+       <width>241</width>
+       <height>111</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Cliquez sur une tourelle pour avoir des informations, l'améliorer ou la revendre.</string>
+     </property>
+     <property name="textFormat">
+      <enum>Qt::AutoText</enum>
+     </property>
+     <property name="scaledContents">
+      <bool>false</bool>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignJustify|Qt::AlignTop</set>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="upgradeTurretButton">
+     <property name="geometry">
+      <rect>
+       <x>20</x>
+       <y>140</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Améliorer</string>
+     </property>
+    </widget>
+    <widget class="QPushButton" name="sellTurretButton">
+     <property name="geometry">
+      <rect>
+       <x>140</x>
+       <y>140</y>
+       <width>98</width>
+       <height>27</height>
+      </rect>
+     </property>
+     <property name="text">
+      <string>Revendre</string>
+     </property>
+    </widget>
+   </widget>
   </widget>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
diff --git a/map.cpp b/map.cpp
index a1cda0083fefa41c4d98fe3627f03631ea639685..c7e74ec275084d54ef018d949226dc71142c5ff5 100644 (file)
--- a/map.cpp
+++ b/map.cpp
@@ -50,8 +50,10 @@ void Map::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
     // CLIC GAUCHE
     if(event->button() == Qt::LeftButton) {
+
         // SELECTION D'UNE TOURELLE (affichage infos)
         if(Defenser* turret = this->getTurretAt((int)(mx/32)*32,(int)(my/32)*32)) {
+
             // Affichage des infos de la tourelle
             emit turretInfosRequest(turret->getInfos());
             turret->setIsSelected(true);
@@ -105,7 +107,8 @@ void Map::removeEnemy(Enemy* ptr) {
     }
 }
 
-QList<Enemy*> Map::getEnemyList(void) const { return _enemies; };
+QList<Enemy*> Map::getEnemyList(void) const { return _enemies; }
+QList<Defenser*> Map::getDefenserList(void) const { return _turrets; }
 
 
 bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) {
@@ -168,6 +171,19 @@ bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) {
             }
             break;
 
+            // Musicien
+            case TYPE::MUSICIEN:
+            if(_player->payMoney(Musician::getBasicCost()))
+            {
+                enoughMoney = true;
+                newTurret = new Musician(((int)(mx/32))*32,
+                                         ((int)(my/32))*32,
+                                         1,
+                                         this);
+                dynamic_cast<Musician*>(newTurret)->applyBonuses(); // Met à jour le bonus des tourelles voisines
+            }
+            break;
+
             // Type inconnu ~ erreur
             default:
             break;
@@ -182,9 +198,16 @@ bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) {
             _turrets.push_back(newTurret);
             // Gestion des clics sur la tourelle
             QObject::connect(this,SIGNAL(setTurretsSelected(bool)),newTurret,SLOT(setIsSelected(bool)));
+
               // On remet à zéro le choix du joueur
             _player->setTurretChoice(TYPE::NONE);
 
+            // Affichage des infos + activation des boutons
+            emit turretInfosRequest(newTurret->getInfos());
+            emit disableTurretUpgradeButton(false);
+            emit disableTurretSellButton(false);
+
+
             return true; // Succès
         }
 
@@ -218,9 +241,19 @@ void Map::removeTurret(void) {
              _turrets[i]->setIsShooting(false);
              // Donne de l'argent au joueur pour la vente
              emit turretSold(_turrets[i]->getCost()/2);
+
+             // Met à jour les bonus 1/2 (voisins immédiats)
+             if(dynamic_cast<Musician*>(_turrets[i]) != 0)
+                dynamic_cast<Musician*>(_turrets[i])->removeBonuses();
+
              // Retire l'objet de la map et de la liste
-             this->removeItem(_turrets[i]);
+             //this->removeItem(_turrets[i]);
+             delete(_turrets[i]);
              _turrets.removeAt(i);
+
+             // Met à jour les bonus 2/2 (le plateau a changé)
+             emit updateBonuses();
+
              // Désactive les boutons de tourelle
              emit disableTurretUpgradeButton(true);
              emit disableTurretSellButton(true);
diff --git a/map.h b/map.h
index 9d5daf8bb7f88c6e5669c973454fe7fbd83e6185..7815b23537b35f5c381f413e5eb00704aeff2d2e 100644 (file)
--- a/map.h
+++ b/map.h
@@ -47,6 +47,7 @@ public:
     Defenser* getTurretAt(int grid_x,int grid_y);
     EnemyFactory* getWaveGenerator(void) const;
     QList<Enemy*> getEnemyList(void) const;
+    QList<Defenser*> getDefenserList(void) const;
 
 
 public slots:
@@ -61,6 +62,7 @@ signals :
     void turretSold(int);
     void disableTurretUpgradeButton(bool);
     void disableTurretSellButton(bool);
+    void updateBonuses(void);
 };
 
 #endif // MAP_H
index ec142d27c9d419a837ef965ce03ba7868cb4883f..9f6d320ab32ef863c82fb53fe0f1ec86f612df9e 100644 (file)
@@ -36,19 +36,8 @@ void Player::loseLives(int livesLost) {
     if(_lives <= 0){
         _lives = 0;
 
-        //!-- BLOC DE FIN DE PARTIE : Victoire
-        QMessageBox msgBox;
-        msgBox.setText("Fin de partie");
-        msgBox.setInformativeText("Vous avez perdu...");
-        QPushButton *restartButton = msgBox.addButton(tr("Rejouer"), QMessageBox::ActionRole);
-        QPushButton *quitButton = msgBox.addButton(tr("Quitter"), QMessageBox::ActionRole);
-        msgBox.exec();
-        if (msgBox.clickedButton() == (QAbstractButton *) restartButton) {
-
-        }
-        else if (msgBox.clickedButton() == (QAbstractButton *) quitButton)
-             exit(0);
-        // FIN DU BLOC  --!
+        // Fin de partie : Perdu !
+        emit gameLost(QString("Vous avez perdu..."));
     }
 
     emit livesValueChanged(_lives);
@@ -82,6 +71,9 @@ void Player::setTurretChoice(TYPE::TURRET choice) {
         case TYPE::PETANQUE:
             emit setTurret4ButtonDisabled(false);
             break;
+        case TYPE::MUSICIEN:
+            emit setTurret5ButtonDisabled(false);
+            break;
         default:
             break;
         }
@@ -105,6 +97,9 @@ void Player::setTurretChoice(TYPE::TURRET choice) {
         case TYPE::PETANQUE:
             emit setTurret4ButtonDisabled(true);
             break;
+        case TYPE::MUSICIEN:
+            emit setTurret5ButtonDisabled(true);
+            break;
         default:
             break;
         }
@@ -115,7 +110,7 @@ void Player::setTurretChoice1(){this->setTurretChoice(TYPE::PISTOLET_A_EAU);}
 void Player::setTurretChoice2(){this->setTurretChoice(TYPE::LANCE_PIERRES);}
 void Player::setTurretChoice3(){this->setTurretChoice(TYPE::PAINTBALL);}
 void Player::setTurretChoice4(){this->setTurretChoice(TYPE::PETANQUE);}
-
+void Player::setTurretChoice5(){this->setTurretChoice(TYPE::MUSICIEN);}
 
 
 bool Player::payMoney(int amount) {
index ca79d1eaf9c7e16d8dba0d9f42b38771a42e5824..084de8536ad465d9a601bf8605bcdc6370d73b16 100644 (file)
--- a/player.h
+++ b/player.h
@@ -35,6 +35,7 @@ public slots:
     void setTurretChoice2();
     void setTurretChoice3();
     void setTurretChoice4();
+    void setTurretChoice5();
 
 
 signals:
@@ -44,7 +45,9 @@ signals:
     void setTurret2ButtonDisabled(bool);
     void setTurret3ButtonDisabled(bool);
     void setTurret4ButtonDisabled(bool);
+    void setTurret5ButtonDisabled(bool);
     void turretSelected();
+    void gameLost(QString);
 };
 
 #endif // PLAYER_H
diff --git a/tile.h b/tile.h
index 2ed3d2d9e49401c8a8dad2d1b62ebdc282e44a99..d5cf9e81f5cd6632f753fbfa2d9a97ae4f2f69a7 100644 (file)
--- a/tile.h
+++ b/tile.h
@@ -16,7 +16,7 @@ public:
     int getY() const;    
     int getTileNumber(void) const;
     bool turretAllowed(void) const;
-     QPointF getDirection(void) const;
+    QPointF getDirection(void) const;
 
 
     QString TexName(int n);
diff --git a/types.h b/types.h
index 74973784f6987119a8b0879381a9aea19ed52cc8..b63f1b6f5da8b412712ffa0cbf4b2492592d0547 100644 (file)
--- a/types.h
+++ b/types.h
@@ -9,7 +9,7 @@ namespace TYPE {
 typedef enum { NORTH = 1 , SOUTH = 2 , EAST = 4 , WEST = 8, GOAL = 32, UP = 128 } DIRECTION;
 typedef enum { T_RAMPANT = 1, T_VOLANT = 2 } ENTITY;
 typedef enum { CAFARD , FOURMI , GUEPE , MOUSTIQUE } ENEMY;
-typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE } TURRET;
+typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE, MUSICIEN} TURRET;
 
 
 };