bool Wave::isFinished(void) const { return(_waveElements.empty()); }
QString Wave::getDesc(void) const { return _desc; }
-EnemyFactory::EnemyFactory(Map* map):_currentMap(map)
+EnemyFactory::EnemyFactory(Map* map,Player* player):_currentMap(map),_player(player)
{
// Lit le fichier wave correspondant à la map courante
- QFile file("./media/maps/waves.txt");
+ QString filePath = QString("media/maps/waves") + QString::number((int)_player->getDifficulty())+ QString(".txt");
+ QFile file(filePath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
// Extrait chaque vague d'ennemis
QList<Wave*> _mapWaves;
Map* _currentMap;
+ Player* _player;
float _waveTimerStep;
void productEnemy(WaveElement* enemy);
public:
- EnemyFactory(Map* map);
+ EnemyFactory(Map* map,Player* player);
public slots:
void getNextWaveDesc(void);
ui->setupUi(this);
// Lance le jeu automatiquement au démarrage de l'application
+ _gameDifficulty = GAME::EASY;
this->launchGame(parent);
+
+ // Menu par défaut
+ // . Partie en cours
+ QObject::connect(ui->actionRecommencer,SIGNAL(triggered()),this,SLOT(reloadGame()));
+ QObject::connect(ui->actionQuitter,SIGNAL(triggered()),this,SLOT(close()));
+ // . Difficulté
+ QObject::connect(ui->actionFacile,SIGNAL(triggered()),this,SLOT(setGameModeEasy()));
+ QObject::connect(ui->actionPro_gamer,SIGNAL(triggered()),this,SLOT(setGameModeHard()));
+
}
void MainWindow::launchGame(QWidget *parent) {
+
/**
* Initialisation des données du joueur
**/
- _player = new Player(22,10); // 22 - 10
+ _player = new Player(22,10,_gameDifficulty); // 22 - 10
/**
/**
* Interface graphique
**/
+
+ /// Menu principal (difficulté actuellement selectionnée)
+ if(_gameDifficulty == GAME::EASY) {
+ ui->actionFacile->setDisabled(true);
+ ui->actionPro_gamer->setDisabled(false);
+ }
+ else {
+ ui->actionFacile->setDisabled(false);
+ ui->actionPro_gamer->setDisabled(true);
+ }
+
/// Lancement de la prochaine vague
// . Lance la production d'ennemi
ui->launchWaveButton->setDisabled(false);
// Relance le jeu (nb: les éléments de l'ancienne partie seront automatiquement supprimés par l'appel au new)
this->launchGame(this->parentWidget());
+}
+void MainWindow::setGameModeEasy(void){
+ _gameDifficulty=GAME::EASY;
+ this->reloadGame();
+}
+void MainWindow::setGameModeHard(void){
+ _gameDifficulty=GAME::HARD;
+ this->reloadGame();
}
QGraphicsView *_view;
Map* _sceneMap;
Player* _player;
+ GAME::DIFFICULTY _gameDifficulty;
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void launchGame(QWidget *parent);
- void reloadGame(void);
public slots:
void showMapContextMenu(const QPoint& pos);
void endGame(QString msg);
+ void reloadGame(void);
+ void setGameModeEasy(void);
+ void setGameModeHard(void);
};
</widget>
</widget>
</widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>25</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuJeu">
+ <property name="title">
+ <string>Jeu</string>
+ </property>
+ <addaction name="actionRecommencer"/>
+ <addaction name="actionQuitter"/>
+ </widget>
+ <widget class="QMenu" name="menuDifficult">
+ <property name="title">
+ <string>Difficulté</string>
+ </property>
+ <addaction name="actionFacile"/>
+ <addaction name="actionPro_gamer"/>
+ </widget>
+ <addaction name="menuJeu"/>
+ <addaction name="menuDifficult"/>
+ </widget>
+ <action name="actionRecommencer">
+ <property name="text">
+ <string>Recommencer</string>
+ </property>
+ </action>
+ <action name="actionQuitter">
+ <property name="text">
+ <string>Quitter</string>
+ </property>
+ </action>
+ <action name="actionFacile">
+ <property name="text">
+ <string>Facile</string>
+ </property>
+ </action>
+ <action name="actionPro_gamer">
+ <property name="text">
+ <string>Pro gamer</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
Map::Map(QWidget *parent,Player* player):QGraphicsScene(parent),_player(player)
{
// Chargement du contenu de la map
- std::ifstream fichier("media/maps/map.txt");
+ QString filePath = QString("media/maps/map") + QString::number((int)_player->getDifficulty())+ QString(".txt");
+ std::ifstream fichier(filePath.toAscii());
int i, j;
int num;
if(fichier)
fichier.close();
// Générateur de vagues
- _waveGenerator = new EnemyFactory(this);
+ _waveGenerator = new EnemyFactory(this,_player);
// Lancement du timer (boucle principale du jeu)
QObject::connect(&gameTimer, SIGNAL(timeout()), this, SLOT(advance()));
gameTimer.start(1000 / GAME::FPS);
#include <iostream>
-Player::Player(int money,int lives){
+Player::Player(int money,int lives,GAME::DIFFICULTY level){
// Initialise l'argent
(money>0) ? _money = money : _money = DEFAULT_MONEY;
// Intialise le nombre de vies
(lives>0) ? _lives = lives : _lives = DEFAULT_LIVES;
-
+ // Difficulté du jeu
+ _gameDifficulty = level;
// Choix clic
_turretChoice = TYPE::NONE;
int Player::getMoney(void) const { return _money; }
int Player::getLives(void) const { return _lives; }
+GAME::DIFFICULTY Player::getDifficulty(void) const{ return _gameDifficulty; }
+void Player::setDifficulty(GAME::DIFFICULTY level) { _gameDifficulty = level; }
+
TYPE::TURRET Player::getTurretChoice(void) const { return _turretChoice; }
void Player::earnMoney(int money) {
int _money;
int _lives;
+ GAME::DIFFICULTY _gameDifficulty;
TYPE::TURRET _turretChoice;
public:
static const int DEFAULT_MONEY = 100;
static const int DEFAULT_LIVES = 10;
- Player(int money = DEFAULT_MONEY,int lives = DEFAULT_LIVES);
+ Player(int money = DEFAULT_MONEY,int lives = DEFAULT_LIVES,GAME::DIFFICULTY = GAME::EASY);
bool payMoney(int amount);
int getMoney(void) const;
int getLives(void) const;
+ GAME::DIFFICULTY getDifficulty(void) const;
TYPE::TURRET getTurretChoice(void) const;
void setTurretChoice(TYPE::TURRET choice);
+ void setDifficulty(GAME::DIFFICULTY level);
public slots:
namespace GAME {
+typedef enum { EASY = 1, HARD = 2 } DIFFICULTY;
static const short FPS = 60;
}