diff --git a/CMakeLists.txt b/CMakeLists.txt index 81e108f..e728887 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,4 +111,4 @@ if(WIN32) "${QT_ROOT_DIR}/plugins/platforms/qwindows.dll" "$/platforms/" ) -endif() \ No newline at end of file +endif() diff --git a/generateAllHexFantome() b/generateAllHexFantome() new file mode 100644 index 0000000..e69de29 diff --git a/include/Cite.hpp b/include/Cite.hpp index 46265fb..ce73fb3 100644 --- a/include/Cite.hpp +++ b/include/Cite.hpp @@ -3,6 +3,7 @@ #include #include #include +#include class Tuile; @@ -25,7 +26,7 @@ class Cite { - virtual uint32_t compterPoints( int niveau_difficulte=0) const = 0; + virtual uint32_t compterPoints( int niveau_difficulte=0, std::array variantes = {}) const = 0; virtual void afficher() const =0; void QTDraw() const; @@ -47,7 +48,6 @@ class Cite { protected: std::vector tuiles; - static void print_hex(Hexagone*hex, int x, int y, strCalc& calc); static void increase_calc_size_H(strCalc& calc, uint32_t size); static void increase_calc_size_V(strCalc& calc, uint32_t size); @@ -70,10 +70,11 @@ class CiteJoueur : public Cite { ~CiteJoueur()=default; bool placerTuileFromHexRef(Hexagone* hex) override; - uint32_t compterPoints( int niveau_difficulte=0) const override; + uint32_t compterPoints( int niveau_difficulte=0, std::array variantes = {}) const override; void afficher()const override; void addTuile(Tuile* t); + }; class CiteIllu : public Cite{ @@ -81,7 +82,7 @@ class CiteIllu : public Cite{ public: CiteIllu(const Tuile* tuileDeDepart):Cite(tuileDeDepart){}; - uint32_t compterPoints( int niveau_difficulte=0) const override; + uint32_t compterPoints( int niveau_difficulte=0, std::array variantes = {}) const override; bool placerTuileFromHexRef(Hexagone* hex)override{return false; }; void afficher()const override; private: diff --git a/include/Jeu.hpp b/include/Jeu.hpp index dd07fda..1c67c1e 100755 --- a/include/Jeu.hpp +++ b/include/Jeu.hpp @@ -18,8 +18,12 @@ class Pioche; enum class ModeDeJeu { Multi, Solo, - PasCommence }; +enum class Duree { + Courte, + Longue +}; + class Jeu { public: @@ -32,17 +36,16 @@ class Jeu { void afficherTuiles() const; void afficherHexagones() const; - void tourJoueur(Joueur* joueur); - void tourIllu(Illu* illu); // FONCTIONNES AFFICHAGE PARTIE EN MODE CONSOLE void StartMenuC(); - - + void tourJoueur(Joueur* joueur); + void tourIllu(Illu* illu); + void AffFinDePartieC(); // FONCTIONS APPELLES PAR QT ET CONSOLE: - void InitialiserPartie(const std::vector& names, uint32_t difficultyLevel); - + void InitialiserPartie(const std::vector& names, uint32_t difficultyLevel, std::arrayvariantes={}, Duree d=Duree::Courte); + Joueur* gagnant(); //void setDifficultyLevel(uint32_t level) { difficultyLevel = level; } //uint32_t getDifficultyLevel() const { return difficultyLevel; } @@ -61,10 +64,10 @@ class Jeu { Tuile* choisirTuileDuChantier(Joueur* joueur); Tuile* choisirTuileDuChantier(Illu* illu); - inline ModeDeJeu getModeDeJeu() const {return mode; }; // A voir si utile, mode solo ? - //void setGameMode(ModeDeJeu mdj) { mode = mdj; } + inline ModeDeJeu getModeDeJeu() const {return mode; }; uint32_t getNbPlayers() const { return joueurs.size(); } + int getnombreTuilesPioche()const{return nombreTuilesPioche; } void setMaxPlayers(uint32_t n) { joueurs.reserve(n); maxPlayers = n; } uint32_t getMaxPlayers() const { return maxPlayers; } void addJoueur(Joueur* j) { joueurs.push_back(j); } @@ -87,7 +90,8 @@ class Jeu { Jeu(); static Jeu* instance; - ModeDeJeu mode; // A voir pendant développement mode solo, initialiser Jeu avec mode solo + ModeDeJeu mode; + Duree duree; std::vector hexs; std::vector tuilesDepart; std::vector joueurs; @@ -98,9 +102,11 @@ class Jeu { bool QtDisplay = true; int nombreTuilesChantier; - int niveauDeDifficulte; + int niveauDeDifficulte; + std::array variantes; + int nombreTuilesPioche; }; -#endif //JEU_H \ No newline at end of file +#endif //JEU_H diff --git a/include/UI/StartMenu.hpp b/include/UI/StartMenu.hpp index ef890c2..01b342a 100644 --- a/include/UI/StartMenu.hpp +++ b/include/UI/StartMenu.hpp @@ -6,6 +6,10 @@ #include "UI/GamePushButton.hpp" #include #include +#include +#include "Jeu.hpp" + + class StartMenu : public QWidget { Q_OBJECT @@ -13,7 +17,7 @@ class StartMenu : public QWidget { StartMenu(QWidget* parent = nullptr); ~StartMenu() override; signals: - void playerSelectionConfirmed(std::vector players, uint32_t difficultyLevel); + void playerSelectionConfirmed(std::vector players, uint32_t difficultyLevel, std::arrayvariantes, Duree d); private slots: void onConfirmClicked(); @@ -28,8 +32,12 @@ private slots: QComboBox* dificultyComboBox; - + QVBoxLayout* variantesLayout; + + QHBoxLayout* longueurLayout; uint32_t playerCount; uint32_t dificultyLevel; + std::array variantes; + Duree duree; std::vector playerButtons; -}; \ No newline at end of file +}; diff --git a/src/Cite.cpp b/src/Cite.cpp index c71a9c0..a4c114c 100644 --- a/src/Cite.cpp +++ b/src/Cite.cpp @@ -561,7 +561,7 @@ bool CiteJoueur::placerTuileFromHexRef(Hexagone *hex) // updateFantomeOfTuile(tl); } -uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const +uint32_t CiteJoueur::compterPoints( int niveau_difficulte, std::arrayvariantes) const { uint32_t nb_place_bleue = 0; uint32_t nb_place_rouge = 0; @@ -635,6 +635,7 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const { const std::array voisins = h->getVoisins3D(); bool cond = true; + int var = 1; for (int i = 0; i < 6; i++) { @@ -646,8 +647,20 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const } } } - if (cond == true) - points_jaune += 1 * niveau; + //variante si on a une place jaune, on double les points + if(variantes[0]==1){ + for (int i = 0; i < 6; i++){ + if (voisins[i] != nullptr){ + if (voisins[i]->getCouleur() == Couleur::Jaune && voisins[i]->getType() == Type::Place){ + var=2; + } + } + } + } + if (cond == true) points_jaune += 1 * niveau * var; + + + } // calcul points jardins : +1 pt pour chaque jardin if (h->getCouleur() == Couleur::Vert) @@ -659,6 +672,7 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const { const std::array &voisins = h->getVoisins3D(); + int var =1; // on vérifie si entierment entouré au niveau 0 bool cond = true; @@ -674,8 +688,12 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const cond = false; } } - if (cond) - points_violet += 1 * niveau; + if(variantes[2]==1){ + if(niveau>1){ + var = 2; + } + if (cond) points_violet += 1 * niveau * var; + } } // calcul habitation: on doit calculer les groupes d'habitations if (h->getCouleur() == Couleur::Bleu) @@ -718,7 +736,7 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const { bool cond = false; const std::array &voisins = h->getVoisins3D(); - + int var = 1; for (int i = 0; i < 6; i++) { if (voisins[i] != nullptr) @@ -731,8 +749,24 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const cond = true; } } - if (cond) - points_rouge += 1 * niveau; + if(variantes[4]==1){ + int cases_vides = 0; + for (int i = 0; i < 6; i++){ + if (voisins[i] != nullptr){ + if (voisins[i]->getType() == Type::Fantome) + cases_vides++; + } + else + { + cases_vides++; + } + + } + if(cases_vides>=3){ + var = 2; + } + } + if (cond) points_rouge += 1 * niveau * var; } } } @@ -748,6 +782,11 @@ uint32_t CiteJoueur::compterPoints( int niveau_difficulte) const if (!habitations_visitees.empty()) { points_bleu = *std::max_element(points_hab.begin(), points_hab.end()); + if(variantes[3]==1){ + if(points_bleu>=10){ + points_bleu=points_bleu*2; + } + } } //std::cout << "printing points : " << points_bleu * nb_place_bleue * 1 << " . " << points_jaune * nb_place_jaune * 2 << " . " << points_rouge * nb_place_rouge * 2 << " . " << points_vert * nb_place_verte * 3 << " . " << points_violet * nb_place_violet * 2 << std::endl; @@ -869,7 +908,7 @@ void Cite::release_hex_fantome() } hexs_fantome.clear(); }; -uint32_t CiteIllu::compterPoints( int niveau_difficulte) const { +uint32_t CiteIllu::compterPoints( int niveau_difficulte, std::array variantes) const { uint32_t nb_carriere = 0; diff --git a/src/Jeu.cpp b/src/Jeu.cpp index 7db8467..f7ad339 100755 --- a/src/Jeu.cpp +++ b/src/Jeu.cpp @@ -64,7 +64,7 @@ void Jeu::EndGame() // Fin opérations de singleton // Constructeur créant les tuilesCité de la partie -Jeu::Jeu() : mode(ModeDeJeu::Solo), niveauDeDifficulte(0), pioche(*this) +Jeu::Jeu() : mode(ModeDeJeu::Solo), niveauDeDifficulte(0), pioche(*this), nombreTuilesPioche(61), duree(Duree::Courte) { // Définition des différentes quantités d'hexagones dans chaque catégorie @@ -145,7 +145,8 @@ Jeu::Jeu() : mode(ModeDeJeu::Solo), niveauDeDifficulte(0), pioche(*this) void Jeu::StartMenuC() { std::vector names; - + std::array variantes; + std::cout << "\n=============================" << std::endl; std::cout << "Bienvenue sur Akropolis.cpp !" << std::endl; std::cout << "=============================" << std::endl @@ -156,6 +157,32 @@ void Jeu::StartMenuC() std::cout << "Une partie est sur le point de commencer, combien êtes-vous : "; std::cin >> nJoueur; + int index_variante =0; + std::cout<<"Voici les differentes variantes disponibles : "<>reponse; + while (reponse != 'n' && reponse != 'N') + { + + do{ + cout<<"Quelle variante voulez vous ajoutez ? "; + std::cin>>index_variante; + if (index_variante < 0 || index_variante> 2){ + std::cout << "Numero de variante invalide. Dois être compris entre 0 et 4" << std::endl; + } + } while (index_variante < 0 || index_variante> 2); + variantes[index_variante] = 1; + cout<<"Merci. Cette variable a ete ajoute. En voulez vous d'autres ? o/n "; + cin>>reponse; + } + for (int i = 0; i < nJoueur; i++) { @@ -188,15 +215,36 @@ void Jeu::StartMenuC() } } while (this->niveauDeDifficulte < 0 || this->niveauDeDifficulte > 2); } - - j->InitialiserPartie(names, this->niveauDeDifficulte); // difficulté 0 par défaut en mode console + std::cout<<"Voulez vous faire une partie courte ? o/n"; + std::cin>>reponse; + while(reponse != 'o' && reponse !='n'){ + std::cout<<"\nreponse invalide réesayer "; + std::cin>>reponse; + } + Duree d=Duree::Courte; + if(reponse=='n'){ + d=Duree::Longue; + } + j->InitialiserPartie(names, this->niveauDeDifficulte,variantes, d); // difficulté 0 par défaut en mode console } -void Jeu::InitialiserPartie(const std::vector &names, uint32_t difficultyLevel) +void Jeu::InitialiserPartie(const std::vector &names, uint32_t difficultyLevel, std::array variantes, Duree d) { std::cout << "\n--- Initialisation de la partie ---\n"; nombreTuilesChantier = names.size() + 2; niveauDeDifficulte = difficultyLevel; + this->variantes = variantes; + if(names.size()>1){ + this->mode= ModeDeJeu::Multi; + } + //gestion de la duree de la partie --> si la duree est courte on doit modifier le nombre de tuile + this->duree= d; + if(duree==Duree::Courte){ + nombreTuilesPioche = 12 * names.size() + 13; + if(mode==ModeDeJeu::Solo){ + nombreTuilesPioche = 12 * 2 +13 ; + } + } for (size_t i = 0; i < names.size(); i++) { @@ -300,13 +348,7 @@ void Jeu::Lancer() } } } - std::cout << "============== FIN DE PARTIE =====================\n"; - std::cout << "AFFICHAGE DES SCORES \n"; - for (auto &j : joueurs) - { - std::cout << j->getNom() << " : "; - std::cout << j->getCite()->compterPoints(niveauDeDifficulte) << " points" << std::endl; - } + this->AffFinDePartieC(); } int Jeu::choisirHexagoneDeReference(Tuile *t) @@ -586,3 +628,30 @@ Tuile *Jeu::choisirTuileDuChantier(Illu *illu) chantier.erase(chantier.begin()); return t; } + + + +Joueur* Jeu::gagnant(){ + Joueur* vainqueur = this->joueurs.back(); + int points_vainqueurs = this->joueurs.back()->getCite()->compterPoints(this->niveauDeDifficulte,this->variantes); + for(auto j : this->joueurs){ + int points = j->getCite()->compterPoints(this->niveauDeDifficulte,this->variantes); + if(points>=points_vainqueurs){ + vainqueur = j ; + points_vainqueurs ; + } + } + return vainqueur; +} + + +void Jeu::AffFinDePartieC(){ + std::cout << "============== FIN DE PARTIE =====================\n"; + std::cout<<"Le gagnant de la partie est le joueur "<gagnant()->getNom() ; + std::cout<<"Voici les différents scores : "<getNom() << " : "; + std::cout << j->getCite()->compterPoints(niveauDeDifficulte, variantes) << " points" << std::endl; + } +} diff --git a/src/Pioche.cpp b/src/Pioche.cpp index 192fd62..5920c70 100644 --- a/src/Pioche.cpp +++ b/src/Pioche.cpp @@ -15,10 +15,12 @@ void Pioche::init() { srand(static_cast(time(nullptr))); seedInit = true; } - + int i = 1; for (auto t : jeuRef.getTuilesCite()) { - if (t != nullptr) + if (t != nullptr && i<= jeuRef.getnombreTuilesPioche()) tuiles.push_back(t); + + i++; } } diff --git a/src/UI/StartMenu.cpp b/src/UI/StartMenu.cpp index 8a626a4..da11a21 100644 --- a/src/UI/StartMenu.cpp +++ b/src/UI/StartMenu.cpp @@ -3,16 +3,16 @@ #include #include #include - +#include #include StartMenu::StartMenu(QWidget* parent) : QWidget(parent), layout(new QVBoxLayout(this)), decBtn(new QPushButton("Enlever joueurs")), incBtn(new QPushButton("Ajouter joueurs")), - confirmBtn(new GamePushButton("Confirmer")), playerCount(1), dificultyLevel(0), + confirmBtn(new GamePushButton("Confirmer")), playerCount(1), dificultyLevel(0),variantes({}), lineEditLayout(new QVBoxLayout()), countInput(new QLineEdit()), - dificultyComboBox(new QComboBox()) + dificultyComboBox(new QComboBox()), variantesLayout(new QVBoxLayout), longueurLayout(new QHBoxLayout) { QHBoxLayout* btnLayout = new QHBoxLayout(); @@ -32,6 +32,8 @@ StartMenu::StartMenu(QWidget* parent) incBtn->setFixedWidth(120); decBtn->setFixedWidth(120); + + // Ligne de difficulté (label + combobox) QWidget* difficultyRow = new QWidget(); QHBoxLayout* diffLayout = new QHBoxLayout(difficultyRow); @@ -42,6 +44,32 @@ StartMenu::StartMenu(QWidget* parent) dificultyComboBox->addItem("Métagénès (niveau Moyen)"); dificultyComboBox->addItem("Callicratès (niveau Difficile)"); + + //Selection de variantes (label + checks boxs) + QLabel* var = new QLabel("Variantes règles : "); + QCheckBox* marche = new QCheckBox("Variante marché"); + //QCheckBox* jardin = new QCheckBox("Variante jardin NON DISPO"); + QCheckBox* temple = new QCheckBox("Variante temple"); + QCheckBox* habitations = new QCheckBox("Variante habitations"); + QCheckBox* caserne = new QCheckBox("Variante caserne"); + + + + + variantesLayout->addWidget(var); + variantesLayout->addWidget(marche); + //variantesLayout->addWidget(jardin); //NON DISPO + variantesLayout->addWidget(temple); + variantesLayout->addWidget(habitations); + variantesLayout->addWidget(caserne); + + //Selection partie longue + QLabel* longueur = new QLabel("Voulez vous faire une partie longue ? "); + QCheckBox* longue = new QCheckBox("oui"); + longueurLayout->addWidget(longueur); + longueurLayout->addWidget(longue); + + connect(dificultyComboBox, &QComboBox::currentIndexChanged, this, [this](int index) { dificultyLevel = static_cast(index); }); @@ -103,6 +131,36 @@ StartMenu::StartMenu(QWidget* parent) } }); + //connexion des check box avec variantes + connect(marche, &QCheckBox::toggled, this, [this](bool checked) { + variantes[0] = checked ? 1 : 0; + }); + + //variante jardin non dispo + //connect(jardin, &QCheckBox::toggled, this, [this](bool checked) { + // variantes[1] = checked ? 1 : 0; + //}); + connect(temple, &QCheckBox::toggled, this, [this](bool checked) { + variantes[2] = checked ? 1 : 0; + }); + connect(habitations, &QCheckBox::toggled, this, [this](bool checked) { + variantes[3] = checked ? 1 : 0; + }); + + connect(caserne, &QCheckBox::toggled, this, [this](bool checked) { + variantes[4] = checked ? 1 : 0; + }); + + connect(longue, &QCheckBox::toggled, this, [this](bool checked) { + if(checked){ + duree = Duree::Longue; + }else{ + duree = Duree::Courte; + } + }); + + + connect(confirmBtn, &QPushButton::clicked, this, &StartMenu::onConfirmClicked); // Champ du premier joueur (min = 1) @@ -114,13 +172,18 @@ StartMenu::StartMenu(QWidget* parent) layout->addLayout(btnLayout); layout->addLayout(lineEditLayout); - // Ajoute la ligne difficulté (label + combobox) et le bouton Confirmer + // Ajoute la ligne difficulté (label + combobox), choix des variantes, choix duree et le bouton Confirmer layout->addWidget(difficultyRow); + layout->addLayout(variantesLayout); + layout->addLayout(longueurLayout); layout->addWidget(confirmBtn); + // Afficher la difficulté uniquement quand playerCount == 1 difficultyRow->setVisible(playerCount == 1); + + setLayout(layout); } StartMenu::~StartMenu() = default; @@ -144,7 +207,7 @@ void StartMenu::onConfirmClicked() players.push_back(lineEdit->text().toStdString()); } - emit playerSelectionConfirmed(players, dificultyLevel); + emit playerSelectionConfirmed(players, dificultyLevel, variantes, duree); } diff --git a/src/UI/mainwindow.cpp b/src/UI/mainwindow.cpp index d71d4fa..59d3065 100644 --- a/src/UI/mainwindow.cpp +++ b/src/UI/mainwindow.cpp @@ -163,4 +163,4 @@ void MainWindow::closeEvent(QCloseEvent *event) // Handle any cleanup before closing Jeu::getInstance()->EndGame(); event->accept(); // Accept the close event -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 0413ffc..043d702 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) Jeu *j = Jeu::getInstance(); if (argc > 1 && std::string(argv[1]) == "--no-gui") - { + { j->setQtDisplay(false); j->StartMenuC(); j->Lancer(); @@ -34,11 +34,11 @@ int main(int argc, char *argv[]) else { - QApplication a(argc, argv); - MainWindow w; - w.show(); + QApplication a(argc, argv); + MainWindow w; + w.show(); - return a.exec(); + return a.exec(); } return 0; @@ -48,4 +48,4 @@ int main(int argc, char *argv[]) std::cout << e.getInfo(); return 1; } -} \ No newline at end of file +}