diff --git a/motus/GameWindow.qml b/motus/GameWindow.qml index edc57a016bb804d669399ad25aefe1c7f48053ed..79a13687f694a526559a623c1ed3c5aeb092f0a7 100644 --- a/motus/GameWindow.qml +++ b/motus/GameWindow.qml @@ -10,41 +10,38 @@ Item { color: "#ffffff" anchors.fill: parent - Clavier { - id: clavier - x: 225 - y: 594 - } - Grid { - id: grid + id: letterGrid columns: 8 rows: 5 - spacing: 5 - width: columns * 50 + (columns - 1) * spacing - height: rows * 50 + (rows - 1) * spacing - - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: clavier.top - anchors.bottomMargin: 100 // un petit espace entre la grille et le clavier + spacing: 4 + anchors.centerIn: parent + width: 600 + height: 400 Repeater { - model: grid.columns * grid.rows - - Rectangle { - width: 50 - height: 50 - color: "lightgray" - border.color: "black" - objectName: "cell_" + index % grid.columns + "_" + Math.floor(index / grid.columns) + model: letterModel // <-- C++ ListModel exposé ici + delegate: Rectangle { + width: 60 + height: 60 + color: "#dddddd" + border.color: "#888" + radius: 5 Text { anchors.centerIn: parent - text: "_" // ou lettre dynamique + text: model.letter font.pixelSize: 24 } } } } + + Clavier { + id: clavier + x: 225 + y: 594 + } } } + diff --git a/motus/jeu.cpp b/motus/jeu.cpp index 4ffac61af533e506a234c3ba144fdcab9043adcf..56be84cd061cc3f0df555f87bffd823c8f20c474 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -3,7 +3,7 @@ #include <QString> -Jeu::Jeu(QObject *parent) : QObject(parent) { +Jeu::Jeu(QObject* rootObject, QObject *parent) : QObject(parent), rootObject(rootObject) { brain = new Brain("./"); } @@ -25,16 +25,28 @@ void Jeu::onClavierClick(QString lettre) { if (!m_letterModel) return; - // if (currentIndex < 40) { // on évite de dépasser la grille - // m_letterModel->setLetter(currentIndex, lettre); - // currentIndex++; - // } + if (currentIndex < 40) { // on évite de dépasser la grille + m_letterModel->setLetter(currentIndex, lettre); + currentIndex++; + } brain->entreLettre(lettre.toStdString()[0]); for (int index = 0; index < 40; index ++) { m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1)); } + + // string lagrille = brain->getGrid(); + // for (int index = 0; index < 40; index ++) { + // string nomCell = "cell_"+to_string(index/8)+"_"+to_string(index%8); + // QObject *cell = rootObject->findChild<QObject*>(nomCell); + // if (cell) { + // cell->setProperty("color", "red"); + // } + // } + + + } @@ -46,8 +58,8 @@ void Jeu::initGame() { void Jeu::startGame() { brain->setFichierDico("words_alpha.txt"); - brain->setNombreEssais(8); - brain->setTailleMots(5); + brain->setNombreEssais(5); + brain->setTailleMots(8); brain->initGame(); diff --git a/motus/jeu.h b/motus/jeu.h index a0e24ccbb072cf50e6908d7ea41f1e0950144860..6d9c03d63ee9935868901cdd166a36b7ce4ccb7c 100644 --- a/motus/jeu.h +++ b/motus/jeu.h @@ -13,7 +13,7 @@ class Jeu : public QObject { Q_PROPERTY(QQuickItem* gameWindow READ getGameWindow NOTIFY gameWindowChanged) public: - explicit Jeu(QObject *parent = nullptr); + explicit Jeu(QObject* rootObject, QObject *parent = nullptr); QString getMotAffiche(); Q_INVOKABLE void onClavierClick(QString lettre); Q_INVOKABLE void initGame(); @@ -28,6 +28,7 @@ signals: private: Brain* brain; + QObject* rootObject; QString mot; QQuickItem* gameWindow; // Pointer to the QQuickItem of the GameWindow LetterModel* m_letterModel = nullptr; // Modèle QML