From 77e24f088234a6bf72510f6908c36d8f553b32b3 Mon Sep 17 00:00:00 2001
From: ppouchet <pierre.pouchet@etu.ec-lyon.fr>
Date: Mon, 24 Mar 2025 15:04:22 +0100
Subject: [PATCH] Nouvelle classe  MotusGame
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Les variables du jeu seront contenues dans une instance de la seule classe MotusGame (nombre de lettres ,mot, nombre d'essais effectués, temps, langue du dictionnaire)
---
 Motus/CMakeLists.txt                     |  5 ++--
 Motus/Main.qml                           | 32 ++++++++++++------------
 Motus/main.cpp                           |  9 ++++---
 Motus/{wordchooser.cpp => motusgame.cpp} |  8 +++---
 Motus/{wordchooser.h => motusgame.h}     | 10 ++++----
 5 files changed, 33 insertions(+), 31 deletions(-)
 rename Motus/{wordchooser.cpp => motusgame.cpp} (84%)
 rename Motus/{wordchooser.h => motusgame.h} (53%)

diff --git a/Motus/CMakeLists.txt b/Motus/CMakeLists.txt
index ee8b9c0..f78948f 100644
--- a/Motus/CMakeLists.txt
+++ b/Motus/CMakeLists.txt
@@ -25,8 +25,8 @@ qt_add_qml_module(appMotus
         Choosebutton.qml
 
     SOURCES
-        wordchooser.h
-        wordchooser.cpp
+
+
 
     RESOURCES
 
@@ -41,6 +41,7 @@ qt_add_qml_module(appMotus
         RESOURCES words_alpha.txt
         RESOURCES words_alpha.txt
         RESOURCES words_alpha.txt
+        SOURCES motusgame.h motusgame.cpp
 )
 
 # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
diff --git a/Motus/Main.qml b/Motus/Main.qml
index bfa85f0..e88fdc6 100644
--- a/Motus/Main.qml
+++ b/Motus/Main.qml
@@ -32,8 +32,8 @@ Window {
 
         Bouton {
             id: bouton
-            x: 76
-            y: 47
+            x: 63
+            y: 56
             _textText: "Générer un mot"
 
             MouseArea {
@@ -43,7 +43,7 @@ Window {
                 width: 400
                 height: 200
                 onClicked: {
-                    let mot = wordChooser.getRandomWord();
+                    let mot = motusGame.getRandomWord();
                     console.log("Mot choisi :", mot);
                     case3._textText = mot;
                     onClicked: case3._textColor="#51c3e1";
@@ -63,19 +63,6 @@ Window {
             y: 249
             buttonText: "Générer un mot"
 
-            MouseArea {
-                id: mouseArea1
-                x: 0
-                y: 0
-                width: 400
-                height: 200
-                onClicked: {
-                    let mot = wordChooser.getRandomWord();
-                    console.log("Mot choisi :", mot);
-                    case3._textText = mot;
-                    onClicked: case3._textColor="#51c3e1";
-                }
-        }
 
 
 
@@ -414,6 +401,19 @@ Window {
                                 event.accepted = true;
                             }
                         }
+        MouseArea {
+            id: mouseArea1
+            x: 0
+            y: 0
+            width: 300
+            height: 200
+            onClicked: {
+                let mot = motusGame.getRandomWord();
+                console.log("Mot choisi :", mot);
+                case3._textText = mot;
+                onClicked: case3._textColor="#51c3e1";
+            }
+        }
         }
 
     Image {
diff --git a/Motus/main.cpp b/Motus/main.cpp
index 200e2c8..f6bb3b7 100644
--- a/Motus/main.cpp
+++ b/Motus/main.cpp
@@ -1,19 +1,20 @@
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlContext>
-#include "WordChooser.h"
+#include "MotusGame.h"
 #include <Qfile>
 
 
 int main(int argc, char *argv[])
 {
-    QFile file(":/words_alpha.txt");
+
     QGuiApplication app(argc, argv);
 
     QQmlApplicationEngine engine;
 
-    WordChooser wordChooser;
-    engine.rootContext()->setContextProperty("wordChooser", &wordChooser);
+    MotusGame motusGame;
+
+    engine.rootContext()->setContextProperty("motusGame", &motusGame);
 
     QObject::connect(
         &engine,
diff --git a/Motus/wordchooser.cpp b/Motus/motusgame.cpp
similarity index 84%
rename from Motus/wordchooser.cpp
rename to Motus/motusgame.cpp
index fd4b79b..4359a02 100644
--- a/Motus/wordchooser.cpp
+++ b/Motus/motusgame.cpp
@@ -1,4 +1,4 @@
-#include "WordChooser.h"
+#include "motusgame.h"
 #include <QFile>
 #include <QTextStream>
 #include <QRandomGenerator>
@@ -7,11 +7,11 @@
 #include <QDebug>
 
 
-WordChooser::WordChooser(QObject *parent) : QObject(parent) {
+MotusGame::MotusGame(QObject *parent) : QObject(parent) {
     loadWords();
 }
 
-void WordChooser::loadWords() {
+void MotusGame::loadWords() {
     QFile file("Motus\\words_alpha.txt");     // ✅ fonctionne avec le .qrc
     if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
         QTextStream in(&file);
@@ -27,7 +27,7 @@ void WordChooser::loadWords() {
     }
 }
 
-QString WordChooser::getRandomWord() {
+QString MotusGame::getRandomWord() {
     if (words.isEmpty()) {
         qDebug() << "❌ Aucune donnée chargée dans words.";
         return "";
diff --git a/Motus/wordchooser.h b/Motus/motusgame.h
similarity index 53%
rename from Motus/wordchooser.h
rename to Motus/motusgame.h
index f04fb5f..f745405 100644
--- a/Motus/wordchooser.h
+++ b/Motus/motusgame.h
@@ -1,14 +1,14 @@
-#ifndef WORDCHOOSER_H
-#define WORDCHOOSER_H
+#ifndef MOTUSGAME_H
+#define MOTUSGAME_H
 
 #include <QObject>
 #include <QString>
 #include <QStringList>
 
-class WordChooser : public QObject {
+class MotusGame : public QObject {
     Q_OBJECT
 public:
-    explicit WordChooser(QObject *parent = nullptr);
+    explicit MotusGame(QObject *parent = nullptr);
     Q_INVOKABLE QString getRandomWord();
 
 private:
@@ -16,4 +16,4 @@ private:
     void loadWords();
 };
 
-#endif // WORDCHOOSER_H
+#endif // MOTUSGAME_H
-- 
GitLab