diff --git a/Motus/CMakeLists.txt b/Motus/CMakeLists.txt index ee8b9c0e624cbb50a68e29ede0d3687657b6441f..f78948fd69d60038e6466eec1f40712630030c5c 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 bfa85f0b7fbb7729adc562b872855f1876d61903..e88fdc6092bbc4d3e412be6b504d8ba9d144fa4c 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 200e2c835f723cf4f9bef26a8648cada4f37a576..f6bb3b7ed67bdc66faa9df57a8de2f96ecf7f5ea 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 fd4b79b5bac0e0b1eeed51100052141c00182015..4359a02e5c945d7d0d9df871d0952e9638434a9c 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 f04fb5fc352993dac7da336ce5dcd33348f03b38..f745405be25a85aa8d8490eeb0ecc4c4f74e570d 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