From 96f3ab1cb09f37e4a45462beddbc6206fda2d8e3 Mon Sep 17 00:00:00 2001
From: ppouchet <pierre.pouchet@etu.ec-lyon.fr>
Date: Mon, 31 Mar 2025 15:41:10 +0200
Subject: [PATCH] Correction : on peut jouer !

---
 Motus/Case.qml      |  8 +++++++-
 Motus/Main.qml      | 29 +++++++++++++++++++++++++----
 Motus/motusgame.cpp |  4 ++--
 Motus/motusgame.h   |  1 +
 4 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/Motus/Case.qml b/Motus/Case.qml
index 0c4e674..4dfb9c1 100644
--- a/Motus/Case.qml
+++ b/Motus/Case.qml
@@ -6,10 +6,16 @@ Item {
     height: 70
     property alias rectangleBorderColor: rectangle.border.color
     property alias rectangleColor: rectangle.color
-    focus: false
+
     property alias rectangleBorderwidth: rectangle.border.width
     property alias _textText: _text.text
 
+    focus: false
+
+    function resetFocus() {
+        focus = true
+    }
+
     Rectangle {
         id: rectangle
         width: 70
diff --git a/Motus/Main.qml b/Motus/Main.qml
index b736f0a..8efa561 100644
--- a/Motus/Main.qml
+++ b/Motus/Main.qml
@@ -134,7 +134,10 @@ Window {
                                 case_focus = caseArray[current_essai * nb_lettres];
                             } else {
                                 // Fin de partie : désactiver l'interface ou afficher un message
-                                mot = "";
+                                if (mot_rentre!=mot){
+
+                                    motusGame.loosetry=true;}
+
                             }
                         } else {
                             // Le mot n'existe pas dans le dictionnaire : colorer toute la ligne en rouge
@@ -200,9 +203,25 @@ Window {
                         MouseArea {
                             anchors.fill: parent
                             cursorShape: Qt.PointingHandCursor
-                            enabled: motusGame.win || motusGame.loosetry || motusGame.loosetime || !motusGame.debut
+                            enabled: motusGame && (motusGame.win || motusGame.loosetry || motusGame.loosetime || !motusGame.debut)
                             onClicked: {
 
+                                // 1. Réinitialiser les indices AVANT de tout
+                                current_essai = 0;
+                                indice_case = 0;
+
+                                // 2. Vider toutes les cases
+                                for (var i = 0; i < caseArray.length; i++) {
+                                    caseArray[i]._textText = "";
+                                    caseArray[i].rectangleColor = "#323232";
+                                    caseArray[i].rectangleBorderColor = "#ffffff";
+                                }
+
+                                    // 3. Vider les touches clavier
+                                for (var j = 0; j < keysArray.length; j++) {
+                                    keysArray[j].keyColor = "#808080";
+                                }
+
                                 // Début d'une partie, désactivation des boutons de régénération, etc.
                                 motusGame.debut=true;
                                 mot = motusGame.getRandomWord(nb_lettres);
@@ -213,6 +232,8 @@ Window {
                                 case3._textText = mot;
                                 mot_split = mot.split("");
                                 console.log(mot_split);
+
+
                             }
                         }
                     }
@@ -507,7 +528,7 @@ Window {
 
     Text {
         y: 32
-        text: "Temps écoulé ! Mot : "+mot
+        text: "Temps écoulé ! Mot : "+ mot
         visible: motusGame && motusGame.loosetime
         color: "red"
         font.pixelSize: 30
@@ -516,7 +537,7 @@ Window {
 
     Text {
         y: 32
-        text: "Nombre d'essais maximum atteint ! Mot : "+mot
+        text: "Nombre d'essais maximum atteint ! Mot : "+ mot
         visible: motusGame && motusGame.loosetry
         color: "red"
         font.pixelSize: 30
diff --git a/Motus/motusgame.cpp b/Motus/motusgame.cpp
index 6f9ba32..a43439e 100644
--- a/Motus/motusgame.cpp
+++ b/Motus/motusgame.cpp
@@ -95,7 +95,7 @@ bool MotusGame::existWord(const QString &word) {
 
 QString MotusGame::getRandomWord(int letterCount) {
     // Vérifier que le nombre de lettres est dans l'intervalle autorisé
-    if (letterCount < 4 || letterCount > 12) {
+    if (letterCount < 5 || letterCount > 12) {
         qDebug() << "❌ Nombre de lettres invalide. Choisissez un nombre entre 4 et 12.";
         return "";
     }
@@ -131,7 +131,7 @@ void MotusGame::setDictionnaryChoosed(const QString &value) {
 void MotusGame::startTimer() {
     qDebug() << "🔁 startTimer() appelé";
 
-    remainingTime = 5;
+    remainingTime = duree_timer;
     emit timerUpdated();
 
     countdownTimer->stop();
diff --git a/Motus/motusgame.h b/Motus/motusgame.h
index eeebd32..5963e2e 100644
--- a/Motus/motusgame.h
+++ b/Motus/motusgame.h
@@ -84,6 +84,7 @@ private:
     bool loosetime = false;
     bool win = false;
     bool debut = false;
+    int duree_timer=120;
 
     void loadWords();
 
-- 
GitLab