diff --git a/motus/jeu.cpp b/motus/jeu.cpp index 14ace9f98104e3f6dc9bc5d670148a1186221d13..4a14519679700696a5cbe20ea24a51c016c0038a 100644 --- a/motus/jeu.cpp +++ b/motus/jeu.cpp @@ -4,11 +4,8 @@ #include <QQmlContext> -Jeu::Jeu(QQmlApplicationEngine* engine, QObject *parent) : QObject(parent), engine(engine) { +Jeu::Jeu(QQmlApplicationEngine* engine, int widht, int height, QObject *parent) : QObject(parent), width(width), height(height), engine(engine) { brain = new Brain("./"); - - width = 10; - height = 7; } int Jeu::getWidth() {return width;} diff --git a/motus/jeu.h b/motus/jeu.h index 0fe6d484d53ae725654f016f4fa5484feca5cda5..d612224a37680d62eb451c9a9d3c8f897d13725c 100644 --- a/motus/jeu.h +++ b/motus/jeu.h @@ -14,7 +14,7 @@ class Jeu : public QObject { Q_PROPERTY(QQuickItem* gameWindow READ getGameWindow NOTIFY gameWindowChanged) public: - explicit Jeu(QQmlApplicationEngine* engine, QObject *parent = nullptr); + explicit Jeu(QQmlApplicationEngine* engine, int width, int height, QObject *parent = nullptr); QString getMotAffiche(); Q_INVOKABLE void onClavierClick(QString lettre); Q_INVOKABLE void initGame(); diff --git a/motus/lettermodel.cpp b/motus/lettermodel.cpp index 1b6d87410bad5d0e453d305adfabf818262a46bf..938f55e2e31494f9d924082923df26f1f1f8446a 100644 --- a/motus/lettermodel.cpp +++ b/motus/lettermodel.cpp @@ -1,11 +1,10 @@ #include "lettermodel.h" -LetterModel::LetterModel(QObject *parent) +LetterModel::LetterModel(int width, int height, QObject *parent) : QAbstractListModel(parent) { - // Initialiser 40 lettres avec "_" - m_letters.fill("_", 40); - m_states.fill(0,40); + m_letters.fill("_", width*height); + m_states.fill(0,width*height); } int LetterModel::rowCount(const QModelIndex &parent) const { diff --git a/motus/lettermodel.h b/motus/lettermodel.h index 918451d1a4953dc0ec4a9e2d579f74658e11b8de..e540b9a43bb37fd1d5591053c00e1c8cbda7dd38 100644 --- a/motus/lettermodel.h +++ b/motus/lettermodel.h @@ -13,7 +13,7 @@ public: StateRole }; - explicit LetterModel(QObject *parent = nullptr); + explicit LetterModel(int width, int height, QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; diff --git a/motus/main.cpp b/motus/main.cpp index 01e2c53d3da3a08fc51383acf06ca3b1c9fcc017..1efe6a2cfba7c6cbed133489f6b649d0cdeb3a08 100644 --- a/motus/main.cpp +++ b/motus/main.cpp @@ -13,9 +13,11 @@ int main(int argc, char *argv[]) { qmlRegisterType<VraieCase>("motus", 1, 0, "VraieCase"); + int width = 10; + int height = 8; // Charger l'interface utilisateur (QML) - LetterModel letterModel; + LetterModel letterModel(width, height); engine.rootContext()->setContextProperty("letterModel", &letterModel); engine.loadFromModule("motus", "Main"); @@ -24,7 +26,7 @@ int main(int argc, char *argv[]) { QQuickItem *parentItem = rootItem; - Jeu jeu(&engine); + Jeu jeu(&engine, width, height); jeu.setLetterModel(&letterModel); engine.rootContext()->setContextProperty("jeu", &jeu);