From 3bb2e305eafc1f8b463c24627fc6cc86f23a9490 Mon Sep 17 00:00:00 2001 From: cboissie Date: Tue, 31 May 2011 01:15:42 +0200 Subject: [PATCH] The musician is now available ! (NB: notices that the bonus is a percent, so "int*percent" -> "int" ! --- defenser.cpp | 229 ++++++++++++++++++++----- defenser.h | 50 +++++- enemy.cpp | 2 + enemyfactory.cpp | 18 +- enemyfactory.h | 5 +- mainwindow.cpp | 40 ++++- mainwindow.h | 1 + mainwindow.ui | 431 +++++++++++++++++++++++++---------------------- map.cpp | 37 +++- map.h | 2 + player.cpp | 23 +-- player.h | 3 + tile.h | 2 +- types.h | 2 +- 14 files changed, 557 insertions(+), 288 deletions(-) diff --git a/defenser.cpp b/defenser.cpp index 691d5f8..7ffb77e 100644 --- a/defenser.cpp +++ b/defenser.cpp @@ -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(bonusTarget) == 0) + bonusTarget->removeBonus(); + } //eof + }// eof + +} diff --git a/defenser.h b/defenser.h index cc7041c..3de02fd 100644 --- a/defenser.h +++ b/defenser.h @@ -1,6 +1,7 @@ #ifndef DEFENSER_H #define DEFENSER_H +#include #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 diff --git a/enemy.cpp b/enemy.cpp index 143c474..d3d7fc0 100644 --- 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(); diff --git a/enemyfactory.cpp b/enemyfactory.cpp index 4d751c4..fed6467 100644 --- a/enemyfactory.cpp +++ b/enemyfactory.cpp @@ -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; diff --git a/enemyfactory.h b/enemyfactory.h index fabe4cc..57fcc71 100644 --- a/enemyfactory.h +++ b/enemyfactory.h @@ -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); }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 08f99e3..d5a3fbb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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; } diff --git a/mainwindow.h b/mainwindow.h index 69abdae..b745530 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,6 +33,7 @@ public: public slots: void showMapContextMenu(const QPoint& pos); + void endGame(QString msg); }; diff --git a/mainwindow.ui b/mainwindow.ui index f6fe652..14df2ac 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -41,204 +41,6 @@ 600 - - - - 530 - 10 - 261 - 581 - - - - - - - - 0 - 0 - - - - - 0 - 10 - - - - - 16777215 - 20 - - - - Clique sur le bouton pour commencer. - - - Qt::AlignCenter - - - - - - - Lancer la vague ! - - - - - - - - - Bilou$e - - - - - - - - - - - - - - Vies - - - - - - - - - - - - Défenses - - - - - 20 - 30 - 98 - 27 - - - - Pistolet à eau - - - - - - 130 - 30 - 98 - 27 - - - - Lance-pierres - - - - - - 20 - 60 - 98 - 27 - - - - PaintBall - - - - - - 130 - 60 - 98 - 27 - - - - Pétanque - - - - - - - - true - - - Informations - - - false - - - - - 10 - 20 - 241 - 81 - - - - Cliquez sur une tourelle pour avoir des informations, l'améliorer ou la revendre. - - - Qt::AutoText - - - false - - - Qt::AlignJustify|Qt::AlignTop - - - true - - - - - - 20 - 100 - 98 - 27 - - - - Améliorer - - - - - - 140 - 100 - 98 - 27 - - - - Revendre - - - - - - @@ -281,9 +83,9 @@ - 50 - 560 - 80 + 670 + 60 + 121 26 @@ -291,6 +93,233 @@ Pause + + + + 530 + 10 + 261 + 41 + + + + Clique sur le bouton pour commencer. + + + false + + + Qt::AlignHCenter|Qt::AlignTop + + + true + + + + + + 530 + 60 + 129 + 27 + + + + Lancer la vague ! + + + + + + 530 + 100 + 261 + 81 + + + + + + + Bilou$e + + + + + + + + + + + + 530 + 190 + 261 + 81 + + + + + + + Vies + + + + + + + + + + + + 530 + 280 + 259 + 126 + + + + Défenses + + + + + 30 + 30 + 98 + 27 + + + + Pistolet à eau + + + + + + 140 + 30 + 98 + 27 + + + + Lance-pierres + + + + + + 30 + 60 + 98 + 27 + + + + PaintBall + + + + + + 140 + 60 + 98 + 27 + + + + Pétanque + + + + + + 80 + 90 + 101 + 27 + + + + Musicien + + + + + + true + + + + 530 + 400 + 259 + 191 + + + + Informations + + + false + + + + + 10 + 20 + 241 + 111 + + + + Cliquez sur une tourelle pour avoir des informations, l'améliorer ou la revendre. + + + Qt::AutoText + + + false + + + Qt::AlignJustify|Qt::AlignTop + + + true + + + + + + 20 + 140 + 98 + 27 + + + + Améliorer + + + + + + 140 + 140 + 98 + 27 + + + + Revendre + + + diff --git a/map.cpp b/map.cpp index a1cda00..c7e74ec 100644 --- 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 Map::getEnemyList(void) const { return _enemies; }; +QList Map::getEnemyList(void) const { return _enemies; } +QList 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(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(_turrets[i]) != 0) + dynamic_cast(_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 9d5daf8..7815b23 100644 --- a/map.h +++ b/map.h @@ -47,6 +47,7 @@ public: Defenser* getTurretAt(int grid_x,int grid_y); EnemyFactory* getWaveGenerator(void) const; QList getEnemyList(void) const; + QList 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 diff --git a/player.cpp b/player.cpp index ec142d2..9f6d320 100644 --- a/player.cpp +++ b/player.cpp @@ -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) { diff --git a/player.h b/player.h index ca79d1e..084de85 100644 --- 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 2ed3d2d..d5cf9e8 100644 --- 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 7497378..b63f1b6 100644 --- 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; }; -- 2.43.0