(also found a bug with right click : turrets placed with right click don't search any target in the current enemy list)
* 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();
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:
float _targetX;
float _targetY;
bool _isShooting;
+ Map* _map;
+
+
};
/**
class WaterGun : public Defenser
{
-
Q_OBJECT
public:
protected:
void advance(int phase);
void updateStats(void);
- Map* _map;
public slots:
void shootTarget(void);
_view->setCacheMode(QGraphicsView::CacheBackground);
_view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+
_view->show();
// Lancement du timer (boucle principale du jeu)
/**
* 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
// . 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)));
{
// TODO CHANGER ADD TURRET
if(selectedItem == createTurret1)
- _sceneMap->addTurretAt(mousePos.x(),mousePos.y());
+ _sceneMap->addTurretAt(TYPE::PISTOLET_A_EAU,mousePos.x(),mousePos.y());
}
}
#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"
<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>
}
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);
}
// CLIC GAUCHE : POSE DE TOURELLE
if(event->button() == Qt::LeftButton)
- this->addTurretAt(mx,my);
+ this->addTurretAt(_player->getTurretChoice(),mx,my);
}
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; }
Q_OBJECT
- // QList<int>* _ennemyList;
EnemyFactory* _waveGenerator;
Tile* _mapTiles[16][16];
QList<Enemy*> _enemies; // OPTIMISATION DES RECHERCHES D'ENNEMI
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;
public slots:
void removeEnemy(Enemy* ptr);
-
};
#endif // MAP_H
#include "player.h"
+#include <iostream>
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) {
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
else
return false; // Paiement impossible
}
-
#define PLAYER_H
#include <QObject>
+#include "types.h"
class Player : public QObject
{
int _money;
int _lives;
+ TYPE::TURRET _turretChoice;
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);
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;
}