From 2e97628cba1b9faf3541cc63dec3c6c81becc307 Mon Sep 17 00:00:00 2001 From: Ulysse Durand <ulysse.durand@ens-lyon.fr> Date: Fri, 11 Apr 2025 22:25:35 +0200 Subject: [PATCH] onavance --- motus/GameWindow.qml | 4 ++-- motus/jeu.cpp | 11 ++++++++--- motus/jeu.h | 7 +++++-- motus/main.cpp | 3 +-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index 3e77f67..79f4c4e 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -12,8 +12,8 @@ Item { Grid { id: letterGrid - columns: 8 - rows: 5 + columns: jeu.getWidth() + rows: jeu.getHeight() spacing: 4 anchors.centerIn: parent width: 600 diff --git a/motus/jeu.cpp b/motus/jeu.cpp index 96a47bd..02a6761 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -1,15 +1,19 @@ #include "jeu.h" #include <iostream> #include <QString> +#include <QQmlContext> -Jeu::Jeu(QObject* rootObject, QObject *parent) : QObject(parent), rootObject(rootObject) { +Jeu::Jeu(QQmlApplicationEngine* engine, QObject *parent) : QObject(parent), engine(engine) { brain = new Brain("./"); - width = 8; - height = 5; + width = 10; + height = 7; } +int Jeu::getWidth() {return width;} +int Jeu::getHeight(){return height;} + QString Jeu::getMotAffiche() { return mot; } @@ -36,6 +40,7 @@ void Jeu::initGame() { void Jeu::startGame() { + engine->rootContext()->setContextProperty("jeu", this); brain->setFichierDico("words_alpha.txt"); brain->setNombreEssais(height); diff --git a/motus/jeu.h b/motus/jeu.h index 056333a..0fe6d48 100644 --- a/motus/jeu.h +++ b/motus/jeu.h @@ -4,6 +4,7 @@ #include <QObject> #include <QQuickItem> #include <QQmlComponent> +#include <QQmlApplicationEngine> #include "brain.h" #include "lettermodel.h" @@ -13,10 +14,12 @@ class Jeu : public QObject { Q_PROPERTY(QQuickItem* gameWindow READ getGameWindow NOTIFY gameWindowChanged) public: - explicit Jeu(QObject* rootObject, QObject *parent = nullptr); + explicit Jeu(QQmlApplicationEngine* engine, QObject *parent = nullptr); QString getMotAffiche(); Q_INVOKABLE void onClavierClick(QString lettre); Q_INVOKABLE void initGame(); + Q_INVOKABLE int getWidth(); + Q_INVOKABLE int getHeight(); Q_INVOKABLE void startGame(); // pour init depuis QML QQuickItem* getGameWindow() const { return gameWindow; } // Getter for gameWindow void setLetterModel(LetterModel* model); // Setter pour le modèle @@ -28,7 +31,7 @@ signals: private: Brain* brain; - QObject* rootObject; + QQmlApplicationEngine* engine; QString mot; QQuickItem* gameWindow; // Pointer to the QQuickItem of the GameWindow LetterModel* m_letterModel = nullptr; // Modèle QML diff --git a/motus/main.cpp b/motus/main.cpp index 82d58df..01e2c53 100644 --- a/motus/main.cpp +++ b/motus/main.cpp @@ -1,5 +1,4 @@ #include <QGuiApplication> -#include <QQmlApplicationEngine> #include <QQmlContext> #include <QQuickItem> #include <QQmlApplicationEngine> @@ -25,7 +24,7 @@ int main(int argc, char *argv[]) { QQuickItem *parentItem = rootItem; - Jeu jeu(rootObject); + Jeu jeu(&engine); jeu.setLetterModel(&letterModel); engine.rootContext()->setContextProperty("jeu", &jeu); -- GitLab