diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index 3e77f6793a41c90bc45dd45ade6e8c491f66bbb6..79f4c4ec87108b97b574b9f45e4e879496210285 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 96a47bdf2a35d0d2236a23a911c166450da4b3f2..02a6761857c2a336501c24c49ff3623ca7f15fd1 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 056333a1ef52259afec1b9d75e42e9fe6c6091bc..0fe6d484d53ae725654f016f4fa5484feca5cda5 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 82d58df6d1589c0b00cc075e7df9f5402080e9f6..01e2c53d3da3a08fc51383acf06ca3b1c9fcc017 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);