diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index 79a13687f694a526559a623c1ed3c5aeb092f0a7..8fd720e3497b059a4d6a6d0598e081f4cfabf51b 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -20,21 +20,32 @@ Item { height: 400 Repeater { - model: letterModel // <-- C++ ListModel exposé ici + model: letterModel + delegate: Rectangle { width: 60 height: 60 - color: "#dddddd" border.color: "#888" radius: 5 + color: { + switch (model.state) { + case 1: return "yellow"; + case 2: return "red"; + default: return "#dddddd"; + } + } + Text { anchors.centerIn: parent text: model.letter font.pixelSize: 24 } + + } } } + } Clavier { @@ -43,5 +54,5 @@ Item { y: 594 } } -} + diff --git a/motus/brain.cpp b/motus/brain.cpp index 3f097513df60949d82fba4ec2ae0a85c88b63d13..4c363d62a4a1da28d204fffcf24d4319ba8ccfa5 100644 --- a/motus/brain.cpp +++ b/motus/brain.cpp @@ -26,6 +26,17 @@ string Brain::getGrid() { return res; } + +string Brain::getGridStates() { + std::string res = ""; + for (int i = 0; i < mNbEssaisMax; ++i) { + res += lignes[i]->getEtats(); // chaque ligne donne une string d'états + } + return res; +} + + + vector<string> Brain::getTxtFiles() { vector<string> txtFiles; diff --git a/motus/brain.h b/motus/brain.h index 9f0ffe35dad84bdbdbb03be9c754713258f33937..a597890f8fb310dbe5bf64e0ea1d453e888f9236 100644 --- a/motus/brain.h +++ b/motus/brain.h @@ -27,6 +27,7 @@ public: void supprLettre(); string getGrid(); vector<Ligne*> lignes; + string getGridStates(); private: string dicodir; diff --git a/motus/jeu.cpp b/motus/jeu.cpp index 56be84cd061cc3f0df555f87bffd823c8f20c474..51395aa0e0bd8c0fdc5fa7b5d35f8eec35cbadfe 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -27,6 +27,7 @@ void Jeu::onClavierClick(QString lettre) { if (currentIndex < 40) { // on évite de dépasser la grille m_letterModel->setLetter(currentIndex, lettre); + currentIndex++; } @@ -34,7 +35,15 @@ void Jeu::onClavierClick(QString lettre) { brain->entreLettre(lettre.toStdString()[0]); for (int index = 0; index < 40; index ++) { m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1)); + + } + std::string etats = brain->getGridStates(); + for (int index = 0; index < 40; ++index) { + int etat = etats[index] - '0'; // convertit '0', '1', '2' → 0, 1, 2 + m_letterModel->setStates(index, etat); + } + // string lagrille = brain->getGrid(); // for (int index = 0; index < 40; index ++) { diff --git a/motus/lettermodel.cpp b/motus/lettermodel.cpp index bc6337032db52f2d705f7cfc02b4ceaa80adc42b..1b6d87410bad5d0e453d305adfabf818262a46bf 100644 --- a/motus/lettermodel.cpp +++ b/motus/lettermodel.cpp @@ -5,6 +5,7 @@ LetterModel::LetterModel(QObject *parent) { // Initialiser 40 lettres avec "_" m_letters.fill("_", 40); + m_states.fill(0,40); } int LetterModel::rowCount(const QModelIndex &parent) const { @@ -18,19 +19,30 @@ QVariant LetterModel::data(const QModelIndex &index, int role) const { if (role == LetterRole) return m_letters.at(index.row()); + else if (role == StateRole) + return m_states.at(index.row()); return QVariant(); } QHash<int, QByteArray> LetterModel::roleNames() const { return { - { LetterRole, "letter" } + { LetterRole, "letter" }, + { StateRole, "state" } }; } + void LetterModel::setLetter(int index, const QString &value) { if (index >= 0 && index < m_letters.size()) { m_letters[index] = value; emit dataChanged(this->index(index), this->index(index), { LetterRole }); } } + +void LetterModel::setStates(int index, int value) { + if (index >= 0 && index < m_states.size()) { + m_states[index] = value; + emit dataChanged(this->index(index), this->index(index), { StateRole }); + } +} diff --git a/motus/lettermodel.h b/motus/lettermodel.h index fe90feb67010be2c1b2918fcd034823e4702b877..918451d1a4953dc0ec4a9e2d579f74658e11b8de 100644 --- a/motus/lettermodel.h +++ b/motus/lettermodel.h @@ -9,7 +9,8 @@ class LetterModel : public QAbstractListModel { public: enum Roles { - LetterRole = Qt::UserRole + 1 + LetterRole = Qt::UserRole + 1, + StateRole }; explicit LetterModel(QObject *parent = nullptr); @@ -19,7 +20,9 @@ public: QHash<int, QByteArray> roleNames() const override; Q_INVOKABLE void setLetter(int index, const QString &value); + Q_INVOKABLE void setStates(int index, int value); private: QVector<QString> m_letters; + QVector<int> m_states; }; diff --git a/motus/ligne.cpp b/motus/ligne.cpp index 71a17a0a9a2064c71e8d055c463e2f492d27a5cc..edc96500a039219a3871618af775b07d7b9558e3 100644 --- a/motus/ligne.cpp +++ b/motus/ligne.cpp @@ -40,6 +40,15 @@ string Ligne::getMot() { return res; } +string Ligne::getEtats() { + string res =""; + for (int i=0; i<bonmot.length();i++) { + res = res + std::to_string(contenu[i]->getEtat()); + + } + return res; +} + void Ligne::show() { cout << "La ligne : |"; for (int i=0;i<bonmot.length();i++) { diff --git a/motus/ligne.h b/motus/ligne.h index 8c9216268705aacea5ad3e99662bd818429fa4ae..57da94dab52d0eafe72c0ab3c2e7b36b8a9467fb 100644 --- a/motus/ligne.h +++ b/motus/ligne.h @@ -25,6 +25,8 @@ public: vector<VraieCase*> contenu; string getMot(); bool dansMot(char lettre, string mot); + string getEtats(); + private: string bonmot;