Skip to content
Snippets Groups Projects
Commit 77e24f08 authored by Pouchet Pierre's avatar Pouchet Pierre
Browse files

Nouvelle classe MotusGame

Les variables du jeu seront contenues dans une instance de la seule classe MotusGame (nombre de lettres ,mot, nombre d'essais effectués, temps, langue du dictionnaire)
parent ed509626
Branches
No related tags found
No related merge requests found
...@@ -25,8 +25,8 @@ qt_add_qml_module(appMotus ...@@ -25,8 +25,8 @@ qt_add_qml_module(appMotus
Choosebutton.qml Choosebutton.qml
SOURCES SOURCES
wordchooser.h
wordchooser.cpp
RESOURCES RESOURCES
...@@ -41,6 +41,7 @@ qt_add_qml_module(appMotus ...@@ -41,6 +41,7 @@ qt_add_qml_module(appMotus
RESOURCES words_alpha.txt RESOURCES words_alpha.txt
RESOURCES words_alpha.txt RESOURCES words_alpha.txt
RESOURCES words_alpha.txt RESOURCES words_alpha.txt
SOURCES motusgame.h motusgame.cpp
) )
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
......
...@@ -32,8 +32,8 @@ Window { ...@@ -32,8 +32,8 @@ Window {
Bouton { Bouton {
id: bouton id: bouton
x: 76 x: 63
y: 47 y: 56
_textText: "Générer un mot" _textText: "Générer un mot"
MouseArea { MouseArea {
...@@ -43,7 +43,7 @@ Window { ...@@ -43,7 +43,7 @@ Window {
width: 400 width: 400
height: 200 height: 200
onClicked: { onClicked: {
let mot = wordChooser.getRandomWord(); let mot = motusGame.getRandomWord();
console.log("Mot choisi :", mot); console.log("Mot choisi :", mot);
case3._textText = mot; case3._textText = mot;
onClicked: case3._textColor="#51c3e1"; onClicked: case3._textColor="#51c3e1";
...@@ -63,19 +63,6 @@ Window { ...@@ -63,19 +63,6 @@ Window {
y: 249 y: 249
buttonText: "Générer un mot" buttonText: "Générer un mot"
MouseArea {
id: mouseArea1
x: 0
y: 0
width: 400
height: 200
onClicked: {
let mot = wordChooser.getRandomWord();
console.log("Mot choisi :", mot);
case3._textText = mot;
onClicked: case3._textColor="#51c3e1";
}
}
...@@ -414,6 +401,19 @@ Window { ...@@ -414,6 +401,19 @@ Window {
event.accepted = true; event.accepted = true;
} }
} }
MouseArea {
id: mouseArea1
x: 0
y: 0
width: 300
height: 200
onClicked: {
let mot = motusGame.getRandomWord();
console.log("Mot choisi :", mot);
case3._textText = mot;
onClicked: case3._textColor="#51c3e1";
}
}
} }
Image { Image {
......
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlContext> #include <QQmlContext>
#include "WordChooser.h" #include "MotusGame.h"
#include <Qfile> #include <Qfile>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QFile file(":/words_alpha.txt");
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
WordChooser wordChooser; MotusGame motusGame;
engine.rootContext()->setContextProperty("wordChooser", &wordChooser);
engine.rootContext()->setContextProperty("motusGame", &motusGame);
QObject::connect( QObject::connect(
&engine, &engine,
......
#include "WordChooser.h" #include "motusgame.h"
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QRandomGenerator> #include <QRandomGenerator>
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include <QDebug> #include <QDebug>
WordChooser::WordChooser(QObject *parent) : QObject(parent) { MotusGame::MotusGame(QObject *parent) : QObject(parent) {
loadWords(); loadWords();
} }
void WordChooser::loadWords() { void MotusGame::loadWords() {
QFile file("Motus\\words_alpha.txt"); // ✅ fonctionne avec le .qrc QFile file("Motus\\words_alpha.txt"); // ✅ fonctionne avec le .qrc
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file); QTextStream in(&file);
...@@ -27,7 +27,7 @@ void WordChooser::loadWords() { ...@@ -27,7 +27,7 @@ void WordChooser::loadWords() {
} }
} }
QString WordChooser::getRandomWord() { QString MotusGame::getRandomWord() {
if (words.isEmpty()) { if (words.isEmpty()) {
qDebug() << "❌ Aucune donnée chargée dans words."; qDebug() << "❌ Aucune donnée chargée dans words.";
return ""; return "";
......
#ifndef WORDCHOOSER_H #ifndef MOTUSGAME_H
#define WORDCHOOSER_H #define MOTUSGAME_H
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
class WordChooser : public QObject { class MotusGame : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit WordChooser(QObject *parent = nullptr); explicit MotusGame(QObject *parent = nullptr);
Q_INVOKABLE QString getRandomWord(); Q_INVOKABLE QString getRandomWord();
private: private:
...@@ -16,4 +16,4 @@ private: ...@@ -16,4 +16,4 @@ private:
void loadWords(); void loadWords();
}; };
#endif // WORDCHOOSER_H #endif // MOTUSGAME_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment