Skip to content
Snippets Groups Projects
Commit 358b142a authored by Ulysse Durand's avatar Ulysse Durand
Browse files

ÇA MARCHE

parent 9a2f731f
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
}
......@@ -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();
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment