]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
Adding a main menu that allows to :
authorcboissie <clemzbox@gmail.com>
Tue, 31 May 2011 00:33:46 +0000 (02:33 +0200)
committercboissie <clemzbox@gmail.com>
Tue, 31 May 2011 00:33:46 +0000 (02:33 +0200)
- Replay / Quit
- Change difficulty between easy and hard (reload the game)

TODO : make hard map and wave : D

enemyfactory.cpp
enemyfactory.h
mainwindow.cpp
mainwindow.h
mainwindow.ui
map.cpp
media/maps/map1.txt [moved from media/maps/map.txt with 100% similarity]
media/maps/waves1.txt [moved from media/maps/waves.txt with 100% similarity]
player.cpp
player.h
types.h

index bc1fc1b7c237db8302e9e1d635970a5d837c6aa1..67f7237d3964d878ab2f19bdfb7dab996cc3c325 100644 (file)
@@ -74,11 +74,12 @@ WaveElement* Wave::popNextWaveElement(void){
 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
index 57fcc71abd636d49d423b75aa9b2e26f84d1c5e7..b37fb388a14e819405c0b34d134753ca712ee26e 100644 (file)
@@ -47,13 +47,14 @@ class EnemyFactory : public QObject
 
     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);
index fe80fe24b7f2fc53031ae7b9d43ec634310d958e..1e29b2c6a2c89de860555f28819be6b42a3f52d4 100644 (file)
@@ -10,15 +10,26 @@ MainWindow::MainWindow(QWidget *parent) :
     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
 
 
     /**
@@ -38,6 +49,17 @@ void MainWindow::launchGame(QWidget *parent) {
     /**
     * 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);
@@ -178,6 +200,14 @@ void MainWindow::reloadGame(void) {
 
     // 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();
 }
index cebcfc202dcb761a1e883672413e9e6b52922d16..31cced770086a83e3a534588f2c886288d19e3a0 100644 (file)
@@ -26,16 +26,19 @@ class MainWindow : public QMainWindow
     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);
 
 };
 
index 14df2ac608049c40681307d512b2d49fe149eff5..59d58279006da31e8e507c635edbf9624bbd2f04 100644 (file)
     </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/>
diff --git a/map.cpp b/map.cpp
index c7e74ec275084d54ef018d949226dc71142c5ff5..643a599da06cde25bc36e3de1fdc5c7b77313d18 100644 (file)
--- a/map.cpp
+++ b/map.cpp
@@ -8,7 +8,8 @@
 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)
@@ -30,7 +31,7 @@ Map::Map(QWidget *parent,Player* player):QGraphicsScene(parent),_player(player)
     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);
similarity index 100%
rename from media/maps/map.txt
rename to media/maps/map1.txt
similarity index 100%
rename from media/maps/waves.txt
rename to media/maps/waves1.txt
index 9f6d320ab32ef863c82fb53fe0f1ec86f612df9e..b6d75586e30560357ad9fdd6638a80b3ac162e88 100644 (file)
@@ -2,13 +2,14 @@
 #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;
 
@@ -16,6 +17,9 @@ Player::Player(int money,int lives){
 
 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) {
index 084de8536ad465d9a601bf8605bcdc6370d73b16..7982371d5deaa3bedbd6c4985bb544d969ee46c7 100644 (file)
--- a/player.h
+++ b/player.h
@@ -11,6 +11,7 @@ class Player : public QObject
 
     int _money;
     int _lives;
+    GAME::DIFFICULTY _gameDifficulty;
     TYPE::TURRET _turretChoice;
 
 public:
@@ -18,12 +19,14 @@ 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:
diff --git a/types.h b/types.h
index 721eeb166b1511e5813b247c962fa13ac2c003b3..93109a5ae4cd63693c5f78d197143f54e5162a84 100644 (file)
--- a/types.h
+++ b/types.h
@@ -16,6 +16,7 @@ typedef enum { NONE, PISTOLET_A_EAU, LANCE_PIERRES, PAINTBALL, PETANQUE, MUSICIE
 
 namespace GAME {
 
+typedef enum { EASY = 1, HARD = 2 } DIFFICULTY;
 static const short FPS = 60;
 
 }