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

ÇA MARCHE

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