diff --git a/Motus/Main.qml b/Motus/Main.qml index e5f2aded86059ccf1a81d7eb8da49fff9c446cb9..9102161c1e249d1ecab81f609d52def9147ecd69 100644 --- a/Motus/Main.qml +++ b/Motus/Main.qml @@ -63,6 +63,7 @@ Window { } console.log("Mot entré :", mot_entre.toUpperCase()); if (motusGame.existWord(mot_entre.toUpperCase())){ + // Vérification de la proposition sur la ligne actuelle for (var i = 0; i < nb_lettres; i++) { var case_verif = caseArray[current_essai * nb_lettres + i]; @@ -72,14 +73,24 @@ Window { case_verif.rectangleBordercolor = "#42cc3d"; } else { for (var j = 0; j < nb_lettres; j++) { + if (lettre_verif === mot_split[j].toUpperCase()) { case_verif.rectangleColor = "#f0d437"; case_verif.rectangleBordercolor = "#f0d437"; + break; + + } } } } + + if (mot_entre.toUpperCase() === mot.toUpperCase()) { + motusGame.setWinbool(true); + console.log("✅ Victoire !"); + } + // Passage à la ligne suivante si possible if (current_essai < nb_essais - 1) { current_essai++; @@ -121,7 +132,9 @@ Window { Row { id: main_row + anchors.fill: parent + spacing: 150 Rectangle { @@ -148,8 +161,8 @@ Window { // Exemple : affichage d'un mot généré dans un Case enfant Case { id: case3 - x: 373 - y: 103 + x: 131 + y: 8 _textText: "mot test" } MouseArea { @@ -264,8 +277,10 @@ Window { Column { id: center_column - width: 700 - height: 900 + x: 0 + y: 36 + width: 716 + height: 864 spacing: 30 Rectangle { @@ -455,11 +470,21 @@ Window { Text { y: 32 text: "⛔ Temps écoulé !" - visible: motusGame.loosebool + visible: motusGame.loose color: "red" font.pixelSize: 30 anchors.horizontalCenterOffset: 0 anchors.horizontalCenter: parent.horizontalCenter } + Text { + y: 32 + text: "Gagné !" + visible: motusGame.win + color: "green" + font.pixelSize: 30 + anchors.horizontalCenterOffset: 0 + anchors.horizontalCenter: parent.horizontalCenter + } + } diff --git a/Motus/motusgame.cpp b/Motus/motusgame.cpp index b81500e23e591d42cb2a7de90a3f659db7dd7a55..007fe631adabccd7d1bdd69ef7980b624575e7e7 100644 --- a/Motus/motusgame.cpp +++ b/Motus/motusgame.cpp @@ -41,6 +41,12 @@ MotusGame::MotusGame(QObject *parent) : QObject(parent) { } +void MotusGame::stopTimer() { + if (countdownTimer && countdownTimer->isActive()) { + countdownTimer->stop(); + qDebug() << "Timer arrêté."; + } +} // Générer un mot ////////////////////////////////////////////////////////////////////////////////////////// @@ -125,7 +131,7 @@ void MotusGame::setDictionnaryChoosed(const QString &value) { void MotusGame::startTimer() { qDebug() << "🔁 startTimer() appelé"; - remainingTime = 120; + remainingTime = 5; emit timerUpdated(); countdownTimer->stop(); @@ -179,16 +185,18 @@ bool MotusGame::getLoosebool() const { } bool MotusGame::getWinbool() const { - return loose; + return win; } void MotusGame::setLoosebool(bool value){ loose=value; + this->stopTimer(); emit looseChanged(); } void MotusGame::setWinbool(bool value){ win=value; + this->stopTimer(); emit winChanged(); } diff --git a/Motus/motusgame.h b/Motus/motusgame.h index 676660ed2b3b93e2db55db6bc3dbee182cdca5e4..c1c44577a900a728d011e3bfc7625705900ced28 100644 --- a/Motus/motusgame.h +++ b/Motus/motusgame.h @@ -22,9 +22,9 @@ class MotusGame : public QObject { Q_PROPERTY(bool randomizeLetterNumber READ getRandomizeLetterNumber WRITE setRandomizeLetterNumber NOTIFY randomizeLetterNumberChanged) - Q_PROPERTY(bool loosebool READ getLoosebool WRITE setLoosebool NOTIFY looseChanged) + Q_PROPERTY(bool loose READ getLoosebool WRITE setLoosebool NOTIFY looseChanged) - Q_PROPERTY(bool winbool READ getWinbool WRITE setWinbool NOTIFY winChanged) + Q_PROPERTY(bool win READ getWinbool WRITE setWinbool NOTIFY winChanged) @@ -38,6 +38,7 @@ public: Q_INVOKABLE void startTimer(); //Pour le début du timer int getRemainingTime() const; + Q_INVOKABLE void stopTimer(); int getLetterNumber() const; //Pour le nombre de lettres du mot qu'on veut générer void setLetterNumber(int value); @@ -54,6 +55,8 @@ public: + + private: QStringList words;