diff --git a/motus/CMakeLists.txt b/motus/CMakeLists.txt index 108da781b86833fa37b4f8902e8a3bcb6a352f0c..a1e6262b5fc177c3e697b16dea393caaf42e9217 100644 --- a/motus/CMakeLists.txt +++ b/motus/CMakeLists.txt @@ -34,6 +34,7 @@ qt_add_qml_module(appmotus QML_FILES Bouton.qml RESOURCES QML_FILES GameWindow.qml + SOURCES jeu.h jeu.cpp ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index abdd6f38078c95a0d0629db4ebd091a65092b691..6f5bf26fc6766486659d20454279d587aa13d6f9 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -1,3 +1,6 @@ + + + import QtQuick Item { @@ -9,11 +12,38 @@ Item { color: "#ffffff" anchors.fill: parent + // Zone où le mot est affiché + Row { + id: motDisplay + spacing: 10 + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 50 + + Repeater { + model: jeu.motAffiche.split(" ") // Divise la chaîne en lettres et "_" + + Rectangle { + width: 50 + height: 50 + border.color: "#000000" + border.width: 2 + radius: 5 + color: "#eeeeee" + + Text { + anchors.centerIn: parent + text: modelData + font.pixelSize: 20 + } + } + } + } + Clavier { id: clavier x: 225 y: 594 } } - } diff --git a/motus/jeu.cpp b/motus/jeu.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47e842336e820846729c9fdb400b9148f1222b5c --- /dev/null +++ b/motus/jeu.cpp @@ -0,0 +1,23 @@ +#include "jeu.h" +#include <iostream> + +Jeu::Jeu(QObject *parent) : QObject(parent), brain("./") { + brain.setFichierDico("words_alpha.txt"); + brain.setNombreEssais(5); + brain.setTailleMots(5); + brain.initGame(); + + mot = QString::fromStdString(brain.getMot()); // ✅ Conversion std::string → QString + + std::cout << "Mot choisi : " << mot.toStdString() << std::endl; +} + +QString Jeu::getMotAffiche() { + if (mot.isEmpty()) return ""; + + QString affichage = QString(mot.at(0)); + for (int i = 1; i < mot.length(); ++i) { + affichage += " _"; + } + return affichage; +} diff --git a/motus/jeu.h b/motus/jeu.h new file mode 100644 index 0000000000000000000000000000000000000000..6a765dc4ff27c744ec7bdcacce7d7ec321390d94 --- /dev/null +++ b/motus/jeu.h @@ -0,0 +1,23 @@ +#ifndef JEU_H +#define JEU_H + +#include <QObject> +#include "brain.h" + +class Jeu : public QObject { + Q_OBJECT + Q_PROPERTY(QString motAffiche READ getMotAffiche NOTIFY motChanged) + +public: + explicit Jeu(QObject *parent = nullptr); + QString getMotAffiche(); + +signals: + void motChanged(); + +private: + Brain brain; + QString mot; +}; + +#endif // JEU_H diff --git a/motus/main.cpp b/motus/main.cpp index d353e6d15f1a4b21fedb3e778618b26ae9257390..fb3911630b17432a18affe6d9f5da8b75055b8a8 100644 --- a/motus/main.cpp +++ b/motus/main.cpp @@ -1,30 +1,16 @@ #include <QGuiApplication> #include <QQmlApplicationEngine> -#include <iostream> +#include <QQmlContext> +#include "jeu.h" -#include "brain.h" - -using namespace std; - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; - QObject::connect( - &engine, - &QQmlApplicationEngine::objectCreationFailed, - &app, - []() { QCoreApplication::exit(-1); }, - Qt::QueuedConnection); - engine.loadFromModule("motus", "Main"); - Brain brain("./"); - brain.setFichierDico("words_alpha.txt"); - brain.setNombreEssais(5); - brain.setTailleMots(5); - brain.initGame(); - cout << brain.getMot() << endl; + Jeu jeu; + engine.rootContext()->setContextProperty("jeu", &jeu); + + engine.loadFromModule("motus", "Main"); return app.exec(); }