Skip to content
Snippets Groups Projects
Select Git revision
  • db87a9c2cb9989466e7bee02ebd4a1395c99f266
  • main default protected
  • Localisation
3 results

carte_cones.py

Blame
  • ligne.cpp 1.95 KiB
    #include "ligne.h"
    #include "fullligneexception.h"
    #include "emptyligneexception.h"
    #include "iostream"
    #include <cctype>
    using namespace std;
    #include <QString>
    
    Ligne::Ligne(string bonmot) : bonmot(bonmot), positionCurseur(0) {}
    
    void Ligne::initLigne() {
        for (int i = 0; i < bonmot.length(); i++) {
            contenu.push_back(new VraieCase());
        }
    }
    
    bool Ligne::isGameCleared() {
        int nbjustes = 0;
        show();
        for (int i = 0; i < bonmot.length(); i++) {
            char bonnelettre = toupper(bonmot[i]);
            char lettreacomparer = contenu[i]->getLetter();
            int etat1 = (bonnelettre == lettreacomparer) ? 1 : 0;
            int etat2 = Ligne::dansMot(lettreacomparer, bonmot);
            int etat = etat1+etat2;
            contenu[i]->setEtat(etat);
            nbjustes += etat;
        }
    
    
        show();
        return (nbjustes == 2*bonmot.length());
    }
    
    string Ligne::getMot() {
        string res = "";
        for (int i=0;i<bonmot.length();i++) {
            res = res + contenu[i]->getLetter();
        }
        return res;
    }
    
    void Ligne::show() {
        cout << "La ligne : |";
        for (int i=0;i<bonmot.length();i++) {
            if (contenu[i]->getEtat() == 1) {cout << "\033[33m";}
            if (contenu[i]->getEtat() == 2) {cout << "\033[31m";}
            cout << contenu[i]->getLetter();
            if (contenu[i]->getEtat() >= 1) cout << "\033[30m";
        }
        cout << "|" << endl;
    }
    
    bool Ligne::dansMot(char lettre, string mot) {
        for (int i=0;i<mot.length();i++) {
            if (mot[i] == tolower(lettre)) {
                return true;
            }
        }
        return false;
    }
    
    void Ligne::entreLettre(char lettre) {
        if (positionCurseur == bonmot.length()) {
            throw FullLigneException();
        }
        contenu[positionCurseur]->setLetter(lettre);  // Conversion ici
        positionCurseur++;
    }