diff --git a/motus/CMakeLists.txt b/motus/CMakeLists.txt index bd2571fbcdc12fb73f708f2c4fe8716376274d78..2aa1556a6910195b21f94a7de8f5c8f7157506f2 100644 --- a/motus/CMakeLists.txt +++ b/motus/CMakeLists.txt @@ -37,7 +37,7 @@ qt_add_qml_module(appmotus SOURCES jeu.h jeu.cpp SOURCES QML_FILES Case.qml - QML_FILES Grille.qml + QML_FILES SOURCES lettermodel.h lettermodel.cpp ) diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index c4bea739de2ac0eeaf9155fb588451a51f2bf87d..119f2f9990564e72c8425b7a88434e4f0c97ceba 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -13,8 +13,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/Grille.qml b/motus/Grille.qml deleted file mode 100644 index bf3708c533a41bff9ce18a6c0703f3e72bf930c2..0000000000000000000000000000000000000000 --- a/motus/Grille.qml +++ /dev/null @@ -1,18 +0,0 @@ -import QtQuick -import QtQuick.Controls - -Grid { - id: grille - rows: jeu.grilleManager.rows // Get the number of rows dynamically - columns: jeu.grilleManager.columns // Get the number of columns dynamically - spacing: 5 - - // Use a Repeater to populate the grid with cases - Repeater { - model: jeu.grilleManager.cases - delegate: Case { - letter: modelData.letter - etat: modelData.etat - } - } -} diff --git a/motus/brain.cpp b/motus/brain.cpp index ea30506592858244be6a9600c5bbfef080fba848..8d6b5b63fb660a2bd8faaba4e22a0785280128c7 100644 --- a/motus/brain.cpp +++ b/motus/brain.cpp @@ -105,7 +105,7 @@ void Brain::trouveMot() { cout << "Mot de taille : " << mTailleMot << " dans " << dico << endl; while (std::getline(file, line)) { if (line.length() == mTailleMot + 1) { - listeMots.push_back(line.substr(0, 8)); + listeMots.push_back(line.substr(0, mTailleMot)); } } diff --git a/motus/jeu.cpp b/motus/jeu.cpp index 51395aa0e0bd8c0fdc5fa7b5d35f8eec35cbadfe..14ace9f98104e3f6dc9bc5d670148a1186221d13 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -1,39 +1,35 @@ #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("./"); -} -// void Jeu::setMot(const QString& mot) { -// this->mot = mot; -// grilleManager.createGrid(mot.length(), 1); // Utilise la longueur du mot pour la grille -// emit motChanged(); -// } + width = 10; + height = 7; +} +int Jeu::getWidth() {return width;} +int Jeu::getHeight(){return height;} QString Jeu::getMotAffiche() { return mot; } void Jeu::onClavierClick(QString lettre) { - - - if (!m_letterModel) return; - if (currentIndex < 40) { // on évite de dépasser la grille + if (currentIndex < width*height) { m_letterModel->setLetter(currentIndex, lettre); currentIndex++; } - brain->entreLettre(lettre.toStdString()[0]); - for (int index = 0; index < 40; index ++) { + for (int index = 0; index < width*height; index ++) { m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1)); @@ -65,14 +61,13 @@ void Jeu::initGame() { void Jeu::startGame() { + engine->rootContext()->setContextProperty("jeu", this); brain->setFichierDico("words_alpha.txt"); - brain->setNombreEssais(5); - brain->setTailleMots(8); + brain->setNombreEssais(height); + brain->setTailleMots(width); brain->initGame(); - - // grilleManager.createGrid(6, 5); // à synchroniser avec les paramètres du brain } void Jeu::setLetterModel(LetterModel* model) { diff --git a/motus/jeu.h b/motus/jeu.h index 6d9c03d63ee9935868901cdd166a36b7ce4ccb7c..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,11 +31,13 @@ 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 int currentIndex = 0; // Pour suivre où on écrit + int width; + int height; }; #endif // JEU_H diff --git a/motus/ligne.cpp b/motus/ligne.cpp index 8621eb3c705cb6d8d8d9c3a5563cee8f626bdcd7..1029f2bb74eca131f85f2abd6b5fbf1844cb5f46 100644 --- a/motus/ligne.cpp +++ b/motus/ligne.cpp @@ -4,7 +4,6 @@ #include "iostream" #include <cctype> using namespace std; -#include <QString> Ligne::Ligne(string bonmot) : bonmot(bonmot), positionCurseur(0) {} 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);