From a4502cc77aee5120be25793aa3a7d74b571861b7 Mon Sep 17 00:00:00 2001 From: ppouchet <pierre.pouchet@etu.ec-lyon.fr> Date: Mon, 31 Mar 2025 10:51:36 +0200 Subject: [PATCH] =?UTF-8?q?Timer=20:=20s'arr=C3=AAte=20quand=20on=20gagne?= =?UTF-8?q?=20ou=20perd,=20et=20=C3=A9criture=20victoire=20ou=20d=C3=A9fai?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Motus/Main.qml | 35 ++++++++++++++++++++++++++++++----- Motus/motusgame.cpp | 12 ++++++++++-- Motus/motusgame.h | 7 +++++-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Motus/Main.qml b/Motus/Main.qml index e5f2ade..9102161 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 b81500e..007fe63 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 676660e..c1c4457 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; -- GitLab