Skip to content
Snippets Groups Projects
Commit 677f702c authored by Yanis Dziki's avatar Yanis Dziki
Browse files

Merge branch 'master' of gitlab.ec-lyon.fr:durandu/projetcppqt

parents e0e17589 75829c52
No related branches found
No related tags found
No related merge requests found
...@@ -122,7 +122,7 @@ void Brain::trouveMot() { ...@@ -122,7 +122,7 @@ void Brain::trouveMot() {
} }
void Brain::setFichierDico(string fichierDico) {dico = fichierDico;} void Brain::setFichierDico(string fichierDico) {dico = fichierDico;}
void Brain::setNombreEssais(int nbEssais) {mNbEssaisMax = nbEssais;} void Brain::setNombreEssais(int thenbEssais) {mNbEssaisMax = thenbEssais;}
void Brain::setTailleMots(int tailleMot) {mTailleMot = tailleMot;} void Brain::setTailleMots(int tailleMot) {mTailleMot = tailleMot;}
string Brain::getMot() {return mot;} string Brain::getMot() {return mot;}
......
...@@ -4,11 +4,8 @@ ...@@ -4,11 +4,8 @@
#include <QQmlContext> #include <QQmlContext>
Jeu::Jeu(QQmlApplicationEngine* engine, QObject *parent) : QObject(parent), engine(engine) { Jeu::Jeu(QQmlApplicationEngine* engine, int width, int height, QObject *parent) : QObject(parent), width(width), height(height), engine(engine) {
brain = new Brain("./"); brain = new Brain("./");
width = 10;
height = 7;
} }
int Jeu::getWidth() {return width;} int Jeu::getWidth() {return width;}
...@@ -39,19 +36,6 @@ void Jeu::onClavierClick(QString lettre) { ...@@ -39,19 +36,6 @@ void Jeu::onClavierClick(QString lettre) {
int etat = etats[index] - '0'; // convertit '0', '1', '2' → 0, 1, 2 int etat = etats[index] - '0'; // convertit '0', '1', '2' → 0, 1, 2
m_letterModel->setStates(index, etat); m_letterModel->setStates(index, etat);
} }
// 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");
// }
// }
} }
......
...@@ -14,7 +14,7 @@ class Jeu : public QObject { ...@@ -14,7 +14,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(QQmlApplicationEngine* engine, QObject *parent = nullptr); explicit Jeu(QQmlApplicationEngine* engine, int width, int height, 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();
......
#include "lettermodel.h" #include "lettermodel.h"
LetterModel::LetterModel(QObject *parent) LetterModel::LetterModel(int width, int height, QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
// Initialiser 40 lettres avec "_" m_letters.fill("_", width*height);
m_letters.fill("_", 40); m_states.fill(0,width*height);
m_states.fill(0,40);
} }
int LetterModel::rowCount(const QModelIndex &parent) const { int LetterModel::rowCount(const QModelIndex &parent) const {
......
...@@ -13,7 +13,7 @@ public: ...@@ -13,7 +13,7 @@ public:
StateRole StateRole
}; };
explicit LetterModel(QObject *parent = nullptr); explicit LetterModel(int width, int height, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
......
...@@ -13,9 +13,11 @@ int main(int argc, char *argv[]) { ...@@ -13,9 +13,11 @@ int main(int argc, char *argv[]) {
qmlRegisterType<VraieCase>("motus", 1, 0, "VraieCase"); qmlRegisterType<VraieCase>("motus", 1, 0, "VraieCase");
int width = 7;
int height = 6;
// Charger l'interface utilisateur (QML) // Charger l'interface utilisateur (QML)
LetterModel letterModel; LetterModel letterModel(width, height);
engine.rootContext()->setContextProperty("letterModel", &letterModel); engine.rootContext()->setContextProperty("letterModel", &letterModel);
engine.loadFromModule("motus", "Main"); engine.loadFromModule("motus", "Main");
...@@ -24,7 +26,7 @@ int main(int argc, char *argv[]) { ...@@ -24,7 +26,7 @@ int main(int argc, char *argv[]) {
QQuickItem *parentItem = rootItem; QQuickItem *parentItem = rootItem;
Jeu jeu(&engine); Jeu jeu(&engine, width, height);
jeu.setLetterModel(&letterModel); jeu.setLetterModel(&letterModel);
engine.rootContext()->setContextProperty("jeu", &jeu); engine.rootContext()->setContextProperty("jeu", &jeu);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment