]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
New gui element and beginning of the turret upgrade module.
authorcboissie <clemzbox@gmail.com>
Wed, 25 May 2011 00:02:55 +0000 (02:02 +0200)
committercboissie <clemzbox@gmail.com>
Wed, 25 May 2011 00:02:55 +0000 (02:02 +0200)
(also found a bug with right click : turrets placed with right click don't search any target in the current enemy list)

defenser.cpp
defenser.h
mainwindow.cpp
mainwindow.h
mainwindow.ui
map.cpp
map.h
player.cpp
player.h
types.h

index 4941cb521e54de0e167a6433bcc6c8793f1d0054..3446703a4438b235f927e4794431c7f7d5aba2bb 100644 (file)
@@ -8,18 +8,16 @@
 * DEFENSER
 **/
 
-Defenser::Defenser(int posx,int posy,int level,TYPE::ENTITY target)
-    :Entity(posx,posy),_level(level),_target(target) {}
-
+Defenser::Defenser(int posx,int posy,int level,TYPE::ENTITY target,Map* map)
+    :Entity(posx,posy),_level(level),_target(target),_map(map) {}
 
 
 /**
 * PISTOLET A EAU
 **/
 
-
 WaterGun::WaterGun(int posx,int posy,int level,TYPE::ENTITY target,Map* map)
-    : Defenser(posx,posy,level,target),_map(map)
+    : Defenser(posx,posy,level,target,map)
 {
     this->updateStats();
 
index 323894b8e8dcad030e37cb49a40acd31952794b1..27109876ee25d19faa89f93c3d6432ec61c160af 100644 (file)
@@ -13,8 +13,10 @@ class Map;
 
 class Defenser : public Entity
 {
+    Q_OBJECT
+
 public:
-    Defenser(int posx,int posy,int level,TYPE::ENTITY target);
+    Defenser(int posx,int posy,int level,TYPE::ENTITY target,Map* map);
     virtual int getCost(void) const = 0;
 
 protected:
@@ -27,6 +29,9 @@ protected:
     float _targetX;
     float _targetY;
     bool _isShooting;
+    Map* _map;
+
+
 };
 
 /**
@@ -36,7 +41,6 @@ protected:
 
 class WaterGun : public Defenser
 {
-
     Q_OBJECT
 
 public:
@@ -53,7 +57,6 @@ public:
 protected:
     void advance(int phase);
     void updateStats(void);
-    Map* _map;
 
 public slots:
     void shootTarget(void);
index c48374498edabda5af18ea64250c65ded9e108ab..2a609b7947901430389727f1fb35ab536ba6c258 100644 (file)
@@ -27,6 +27,7 @@ MainWindow::MainWindow(QWidget *parent) :
     _view->setCacheMode(QGraphicsView::CacheBackground);
     _view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
 
+
     _view->show();
 
     // Lancement du timer (boucle principale du jeu)
@@ -36,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
     /**
     * Interface graphique
     **/
-    // Lancement de la prochaine vague
+    /// Lancement de la prochaine vague
     // . Lance la production d'ennemi
     QObject::connect(ui->launchWaveButton, SIGNAL(pressed()),_sceneMap->getWaveGenerator(),SLOT(launchWaves()));
     // . Change le texte d'ambiance associé à la vague courante
@@ -45,7 +46,17 @@ MainWindow::MainWindow(QWidget *parent) :
     // . Rend le bouton inactif le temps que la vague se produise
     QObject::connect(_sceneMap->getWaveGenerator(),SIGNAL(setLaunchWaveButtonEnabled(bool)),ui->launchWaveButton,SLOT(setEnabled(bool)));
 
-    // Gestions des compteurs
+
+    /// Boutons de choix de tourelle
+    // . Pistolet à eau
+    QObject::connect(ui->turretButton_PistoletAEau,SIGNAL(pressed()),_player,SLOT(setTurretChoice1()));
+
+
+    // Demande d'informations sur une tourelle
+    // QObject::connect(_sceneMap,SIGNAL(loadTurretInfos(QString)),ui->turretInfoLabel,SLOT(setText(QString)));
+
+
+    /// Gestions des compteurs
     // Argent
     ui->creditCounter->display(_player->getMoney()); // C'est du vol
     QObject::connect(_player,SIGNAL(moneyValueChanged(int)),ui->creditCounter,SLOT(display(int)));
@@ -83,7 +94,7 @@ void MainWindow::showMapContextMenu(const QPoint& pos) {
    {
        // TODO CHANGER ADD TURRET
        if(selectedItem == createTurret1)
-            _sceneMap->addTurretAt(mousePos.x(),mousePos.y());
+           _sceneMap->addTurretAt(TYPE::PISTOLET_A_EAU,mousePos.x(),mousePos.y());
    }
 
 }
index 41e79262a89049b961328858e0da1875469b02ed..237bca8182d395aaaef0ce714146fc84700409da 100644 (file)
@@ -2,13 +2,13 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
-#include "map.h"
 #include <QGraphicsView>
 #include <QGraphicsPixmapItem>
 
 #include <QTimer>
 #include <QTime>
 
+#include "types.h"
 #include "map.h"
 #include "player.h"
 
index 2e2fb93e972eac912123e182363c5c05fb681636..3aa12cc573a25b0c51ca451ac9a489fc105d211a 100644 (file)
      <item>
       <widget class="QGroupBox" name="groupBox">
        <property name="title">
-        <string>GroupBox</string>
+        <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>
      </item>
      <item>
         <bool>true</bool>
        </property>
        <property name="title">
-        <string>GroupBox</string>
+        <string>Informations</string>
        </property>
        <property name="flat">
         <bool>false</bool>
        </property>
-       <widget class="QLabel" name="label_4">
+       <widget class="QLabel" name="turretInfoLabel">
         <property name="geometry">
          <rect>
-          <x>90</x>
-          <y>40</y>
-          <width>67</width>
-          <height>17</height>
+          <x>0</x>
+          <y>20</y>
+          <width>261</width>
+          <height>71</height>
          </rect>
         </property>
         <property name="text">
          <string>TextLabel</string>
         </property>
+        <property name="alignment">
+         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+        </property>
        </widget>
-       <widget class="QPushButton" name="pushButton_2">
+       <widget class="QPushButton" name="upgradeTurretButton">
         <property name="geometry">
          <rect>
           <x>20</x>
-          <y>80</y>
+          <y>90</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
-         <string>PushButton</string>
+         <string>Améliorer</string>
         </property>
        </widget>
-       <widget class="QPushButton" name="pushButton_3">
+       <widget class="QPushButton" name="sellTurretButton">
         <property name="geometry">
          <rect>
           <x>140</x>
-          <y>80</y>
+          <y>90</y>
           <width>98</width>
           <height>27</height>
          </rect>
         </property>
         <property name="text">
-         <string>PushButton</string>
+         <string>Revendre</string>
         </property>
        </widget>
       </widget>
diff --git a/map.cpp b/map.cpp
index c7c685e09b40c2220da12ab547d03bebbd49459e..fc58e4d3828a2c0a2dcb483c03aa2a0669e7117a 100644 (file)
--- a/map.cpp
+++ b/map.cpp
@@ -29,11 +29,6 @@ Map::Map(QWidget *parent,Player* player):QGraphicsScene(parent),_player(player)
     }
     fichier.close();
 
-    /* TEST
-    _entities.push_front(new Cafard(this,32*2,0,1));
-    this->addItem(_entities.first());
-    */
-
     // Générateur de vagues
     _waveGenerator = new EnemyFactory(this);
 }
@@ -48,7 +43,7 @@ void Map::mousePressEvent(QGraphicsSceneMouseEvent *event) {
 
     // CLIC GAUCHE : POSE DE TOURELLE
     if(event->button() == Qt::LeftButton)
-        this->addTurretAt(mx,my);
+        this->addTurretAt(_player->getTurretChoice(),mx,my);
 
 }
 
@@ -91,28 +86,59 @@ void Map::removeEnemy(Enemy* ptr) {
 QList<Enemy*> Map::getEnemyList(void) const { return _enemies; };
 
 
-bool Map::addTurretAt(float mx,float my) {
+bool Map::addTurretAt(TYPE::TURRET turretType,float mx,float my) {
 
     // Vérifie s'il est possible de poser une tourelle à cet emplacement
-    // ... et si le joueur a assez d'argent (le cas échant, il est débité aussitôt
-    if( this->getTileAt(mx/32,my/32).turretAllowed() &&
-        _player->payMoney(WaterGun::getBasicCost())) {
+    if( this->getTileAt(mx/32,my/32).turretAllowed()) {
 
-        this->getTileAt(mx/32,my/32).setHasTurret(true);
-        WaterGun* test = new WaterGun(((int)(mx/32))*32,
-                                          ((int)(my/32))*32,
-                                          1,
-                                          (TYPE::ENTITY)(TYPE::T_RAMPANT | TYPE::T_VOLANT),
-                                          this);
-        this->addItem(test);
+        // On pose une nouvelle tourelle du type souhaité ...
+        // ... si le joueur a assez d'argent (le cas échant, il est débité aussitôt)
+        Defenser* newTurret;
+        bool enoughMoney = false;
 
-        return true; // Succès
+        switch(turretType) {
 
-    }
+            // Pistolet à eau
+            case TYPE::PISTOLET_A_EAU:
+            if(_player->payMoney(WaterGun::getBasicCost()))
+            {
+                enoughMoney = true;
+                newTurret = new WaterGun(((int)(mx/32))*32,
+                                         ((int)(my/32))*32,
+                                         1,
+                                         (TYPE::ENTITY)(TYPE::T_RAMPANT | TYPE::T_VOLANT),
+                                         this);
+            }
+            break;
+
+            // Type inconnu ~ erreur
+            default:
+            break;
+
+         } // eos
+
+        // Ajout de la tourelle et mise à jour des informations de la map
+        if(enoughMoney) {
+            // Le tile contient désormais une tourelle
+            this->getTileAt(mx/32,my/32).setHasTurret(true);
+            // Ajout sur la map
+            this->addItem(newTurret);
+
+            // Gestion des clics sur la tourelle
+            // QObject::connect(newTurret,SIGNAL(turretClicked(QString)),this,SLOT(turretInfosRequest(QString)));
+
+            // On remet à zéro le choix du joueur
+            _player->setTurretChoice(TYPE::NONE);
+
+            return true; // Succès
+        }
+
+    } // End test case libre
 
     return false; // Echec
 }
 
+
 QPoint Map::getStart(void) const { return _startPos; }
 Tile& Map::getTileAt(int x, int y) const { return *_mapTiles[x][y]; }
 EnemyFactory* Map::getWaveGenerator(void) const { return _waveGenerator; }
diff --git a/map.h b/map.h
index c08c255c1baaf20c7ffee76dbfa7ae34734ceecf..6738ec7b74c37be119983b9cc86a868ec6b5fd1b 100644 (file)
--- a/map.h
+++ b/map.h
@@ -21,7 +21,6 @@ class Map : public QGraphicsScene
 
     Q_OBJECT
 
-    // QList<int>* _ennemyList;
     EnemyFactory* _waveGenerator;
     Tile* _mapTiles[16][16];
     QList<Enemy*> _enemies; // OPTIMISATION DES RECHERCHES D'ENNEMI
@@ -29,13 +28,13 @@ class Map : public QGraphicsScene
     QPoint _startPos;
     Player* _player;
 
+    void mousePressEvent(QGraphicsSceneMouseEvent *event);
 
 
 public:
     Map(QWidget* parent,Player* player);
-    void mousePressEvent(QGraphicsSceneMouseEvent *event);
     void addEnemy(Enemy* enemy);
-    bool addTurretAt(float mx,float my);
+    bool addTurretAt(TYPE::TURRET turretType,float mx,float my);
     QPoint getStart(void) const;
     Tile& getTileAt(int x, int y) const;
     EnemyFactory* getWaveGenerator(void) const;
@@ -43,7 +42,6 @@ public:
 
 public slots:
     void removeEnemy(Enemy* ptr);
-
 };
 
 #endif // MAP_H
index 18df21c25d531a4112882f27d57fb99b9ff75877..e3a1873be284fcf0d4f39c8ed41ea4d99c9ef20f 100644 (file)
@@ -1,4 +1,5 @@
 #include "player.h"
+#include <iostream>
 
 
 Player::Player(int money,int lives){
@@ -8,10 +9,14 @@ Player::Player(int money,int lives){
     // Intialise le nombre de vies
     (lives>0) ? _lives = lives : _lives = DEFAULT_LIVES;
 
+    // Choix clic
+    _turretChoice = TYPE::NONE;
+
 }
 
 int Player::getMoney(void) const { return _money; }
 int Player::getLives(void) const { return _lives; }
+TYPE::TURRET Player::getTurretChoice(void) const { return _turretChoice; }
 
 void Player::earnMoney(int amount) {
 
@@ -34,6 +39,14 @@ void Player::loseLives(int livesLost) {
     emit livesValueChanged(_lives);
 }
 
+void Player::setTurretChoice(TYPE::TURRET choice) {
+    _turretChoice = choice;
+    std::cout << "Le joueur a choisi " << choice << std::endl;
+}
+void Player::setTurretChoice1(){this->setTurretChoice(TYPE::PISTOLET_A_EAU);}
+
+
+
 bool Player::payMoney(int amount) {
 
     // Vérifie si le joueur peut payer
@@ -45,4 +58,3 @@ bool Player::payMoney(int amount) {
     else
         return false; // Paiement impossible
 }
-
index ac64172fa7e206d1978372a365947bd819401efe..209b33ef3a4417f855fa9d601496af6fc8e47afd 100644 (file)
--- a/player.h
+++ b/player.h
@@ -2,6 +2,7 @@
 #define PLAYER_H
 
 #include <QObject>
+#include "types.h"
 
 class Player : public QObject
 {
@@ -9,6 +10,7 @@ class Player : public QObject
 
     int _money;
     int _lives;
+    TYPE::TURRET _turretChoice;
 
 public:
 
@@ -19,11 +21,15 @@ public:
     bool payMoney(int amount);
     int getMoney(void) const;
     int getLives(void) const;
+    TYPE::TURRET getTurretChoice(void) const;
+    void setTurretChoice(TYPE::TURRET choice);
+
 
 public slots:
 
     void earnMoney(int amount);
     void loseLives(int livesLost);
+    void setTurretChoice1();
 
 signals:
     void moneyValueChanged(int);
diff --git a/types.h b/types.h
index 19bbba7d3075e5d1377361251302268875935157..de8b39db0fb87a8270bd5cea0d89e62f4cb33c88 100644 (file)
--- a/types.h
+++ b/types.h
@@ -9,6 +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 } ENEMY;
+typedef enum { NONE, PISTOLET_A_EAU } TURRET;
 
 }