diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index 79f4c4ec87108b97b574b9f45e4e879496210285..119f2f9990564e72c8425b7a88434e4f0c97ceba 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -5,9 +5,10 @@ Item { width: 900 height: 800 + Rectangle { id: rectangle - color: "#ffffff" + color: "#8ff0a4" anchors.fill: parent Grid { @@ -20,21 +21,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 { @@ -44,9 +56,3 @@ Item { } } - Loader { - id: pageLoader2 - anchors.centerIn: parent - } -} - diff --git a/motus/Main.qml b/motus/Main.qml index 3603e7738eca6be342ef925aa47618df317ba62e..c9b7a5519a71fa8bad436c286dc70f9a091db921 100644 --- a/motus/Main.qml +++ b/motus/Main.qml @@ -24,14 +24,14 @@ Window { font.pixelSize: 30 } } - +/* MenuDeroulant { id: menuDeroulant x: 38 y: 301 rectangleColor: "#b33939" } - +*/ Bouton { id: bouton x: 360 @@ -48,4 +48,26 @@ Window { anchors.centerIn: parent } + + Text { + id: _text1 + x: 194 + y: 167 + width: 551 + height: 56 + color: "#0e0e0e" + text: qsTr("Projet par Ulysse Durand et Yanis Dziki, ") + font.pixelSize: 30 + } + + Text { + id: _text2 + x: 186 + y: 372 + width: 551 + height: 56 + color: "#0e0e0e" + text: qsTr("Le jeu se lance par défaut avec un 5 essais\n pour des mots de 8 lettres") + font.pixelSize: 30 + } } diff --git a/motus/brain.cpp b/motus/brain.cpp index 23d5cdb5bdbb40376fd36f61dfe7f3bcc0b76a72..8d6b5b63fb660a2bd8faaba4e22a0785280128c7 100644 --- a/motus/brain.cpp +++ b/motus/brain.cpp @@ -35,6 +35,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 b97fe479c44b74a5b3f49cc163791c17eb7116be..0571e51cf6f782cd1380f17f1240b8ed52811507 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 02a6761857c2a336501c24c49ff3623ca7f15fd1..14ace9f98104e3f6dc9bc5d670148a1186221d13 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -24,13 +24,34 @@ void Jeu::onClavierClick(QString lettre) { if (currentIndex < width*height) { m_letterModel->setLetter(currentIndex, lettre); + currentIndex++; } brain->entreLettre(lettre.toStdString()[0]); for (int index = 0; index < width*height; 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 ++) { + // string nomCell = "cell_"+to_string(index/8)+"_"+to_string(index%8); + // QObject *cell = rootObject->findChild<QObject*>(nomCell); + // if (cell) { + // cell->setProperty("color", "red"); + // } + // } + + + } 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 8373c23bc3a76180e6ce3806dd6796d90065ba35..1029f2bb74eca131f85f2abd6b5fbf1844cb5f46 100644 --- a/motus/ligne.cpp +++ b/motus/ligne.cpp @@ -39,6 +39,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;