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

Ça bug moins

parent 4a4b0813
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ qt_add_qml_module(appmotus ...@@ -37,7 +37,7 @@ qt_add_qml_module(appmotus
SOURCES jeu.h jeu.cpp SOURCES jeu.h jeu.cpp
SOURCES SOURCES
QML_FILES Case.qml QML_FILES Case.qml
QML_FILES Grille.qml QML_FILES
SOURCES lettermodel.h lettermodel.cpp SOURCES lettermodel.h lettermodel.cpp
) )
......
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
}
}
}
...@@ -94,7 +94,7 @@ void Brain::trouveMot() { ...@@ -94,7 +94,7 @@ void Brain::trouveMot() {
cout << "Mot de taille : " << mTailleMot << " dans " << dico << endl; cout << "Mot de taille : " << mTailleMot << " dans " << dico << endl;
while (std::getline(file, line)) { while (std::getline(file, line)) {
if (line.length() == mTailleMot + 1) { if (line.length() == mTailleMot + 1) {
listeMots.push_back(line.substr(0, 8)); listeMots.push_back(line.substr(0, mTailleMot));
} }
} }
......
...@@ -5,34 +5,26 @@ ...@@ -5,34 +5,26 @@
Jeu::Jeu(QObject* rootObject, QObject *parent) : QObject(parent), rootObject(rootObject) { Jeu::Jeu(QObject* rootObject, QObject *parent) : QObject(parent), rootObject(rootObject) {
brain = new Brain("./"); 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 = 8;
height = 5;
}
QString Jeu::getMotAffiche() { QString Jeu::getMotAffiche() {
return mot; return mot;
} }
void Jeu::onClavierClick(QString lettre) { 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 < width*height) {
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 < width*height; index ++) {
m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1)); m_letterModel->setLetter(index, QString::fromLatin1(&brain->getGrid()[index], 1));
} }
} }
...@@ -46,12 +38,10 @@ void Jeu::initGame() { ...@@ -46,12 +38,10 @@ void Jeu::initGame() {
void Jeu::startGame() { void Jeu::startGame() {
brain->setFichierDico("words_alpha.txt"); brain->setFichierDico("words_alpha.txt");
brain->setNombreEssais(5); brain->setNombreEssais(height);
brain->setTailleMots(8); brain->setTailleMots(width);
brain->initGame(); brain->initGame();
// grilleManager.createGrid(6, 5); // à synchroniser avec les paramètres du brain
} }
void Jeu::setLetterModel(LetterModel* model) { void Jeu::setLetterModel(LetterModel* model) {
......
...@@ -33,6 +33,8 @@ private: ...@@ -33,6 +33,8 @@ private:
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
int currentIndex = 0; // Pour suivre où on écrit int currentIndex = 0; // Pour suivre où on écrit
int width;
int height;
}; };
#endif // JEU_H #endif // JEU_H
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "iostream" #include "iostream"
#include <cctype> #include <cctype>
using namespace std; using namespace std;
#include <QString>
Ligne::Ligne(string bonmot) : bonmot(bonmot), positionCurseur(0) {} Ligne::Ligne(string bonmot) : bonmot(bonmot), positionCurseur(0) {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment