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()));
}
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++;
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;
// 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
**/
}
-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) {
_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);
}
-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) {
_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);
}
-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) {
_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);
}
/**
-* PAINTBALL
+* PETANQUE
**/
Bowling::Bowling(int posx,int posy,int level,Map* map)
-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) {
_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
+
+}
#ifndef DEFENSER_H
#define DEFENSER_H
+#include <QList>
#include "map.h"
#include "entity.h"
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;
float _rate;
float _range;
int _power;
+ float _powerBonus;
float _targetX;
float _targetY;
Map* _map;
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; }
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:
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:
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
_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) {
_type = DEFAULT_TYPE;
_hp = 6*size*size;
_hpMax = _hp;
+ _stateCounter = 0; // Initialise la machine à état
this->updateStats();
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;
void produceWave(void);
signals:
- void changeWaveDescLabel(QString text);
- void setLaunchWaveButtonEnabled(bool state);
+ void changeWaveDescLabel(QString);
+ void setLaunchWaveButtonEnabled(bool);
+ void gameWon(QString);
};
/**
* 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
_view->setScene(_sceneMap);
_view->setRenderHint(QPainter::Antialiasing);
_view->setCacheMode(QGraphicsView::CacheBackground);
- _view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ _view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
_view->show();
// . 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)));
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
**/
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);
_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;
}
public slots:
void showMapContextMenu(const QPoint& pos);
+ void endGame(QString msg);
};
<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"/>
// 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);
}
}
-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) {
}
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;
_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
}
_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);
Defenser* getTurretAt(int grid_x,int grid_y);
EnemyFactory* getWaveGenerator(void) const;
QList<Enemy*> getEnemyList(void) const;
+ QList<Defenser*> getDefenserList(void) const;
public slots:
void turretSold(int);
void disableTurretUpgradeButton(bool);
void disableTurretSellButton(bool);
+ void updateBonuses(void);
};
#endif // MAP_H
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);
case TYPE::PETANQUE:
emit setTurret4ButtonDisabled(false);
break;
+ case TYPE::MUSICIEN:
+ emit setTurret5ButtonDisabled(false);
+ break;
default:
break;
}
case TYPE::PETANQUE:
emit setTurret4ButtonDisabled(true);
break;
+ case TYPE::MUSICIEN:
+ emit setTurret5ButtonDisabled(true);
+ break;
default:
break;
}
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) {
void setTurretChoice2();
void setTurretChoice3();
void setTurretChoice4();
+ void setTurretChoice5();
signals:
void setTurret2ButtonDisabled(bool);
void setTurret3ButtonDisabled(bool);
void setTurret4ButtonDisabled(bool);
+ void setTurret5ButtonDisabled(bool);
void turretSelected();
+ void gameLost(QString);
};
#endif // PLAYER_H
int getY() const;
int getTileNumber(void) const;
bool turretAllowed(void) const;
- QPointF getDirection(void) const;
+ QPointF getDirection(void) const;
QString TexName(int n);
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;
};