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
Choosebutton.qml
SOURCES
wordchooser.h
wordchooser.cpp
RESOURCES
......@@ -41,6 +41,7 @@ qt_add_qml_module(appMotus
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.
......
......@@ -32,8 +32,8 @@ Window {
Bouton {
id: bouton
x: 76
y: 47
x: 63
y: 56
_textText: "Générer un mot"
MouseArea {
......@@ -43,7 +43,7 @@ Window {
width: 400
height: 200
onClicked: {
let mot = wordChooser.getRandomWord();
let mot = motusGame.getRandomWord();
console.log("Mot choisi :", mot);
case3._textText = mot;
onClicked: case3._textColor="#51c3e1";
......@@ -63,19 +63,6 @@ Window {
y: 249
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 {
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 {
......
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "WordChooser.h"
#include "MotusGame.h"
#include <Qfile>
int main(int argc, char *argv[])
{
QFile file(":/words_alpha.txt");
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
WordChooser wordChooser;
engine.rootContext()->setContextProperty("wordChooser", &wordChooser);
MotusGame motusGame;
engine.rootContext()->setContextProperty("motusGame", &motusGame);
QObject::connect(
&engine,
......
#include "WordChooser.h"
#include "motusgame.h"
#include <QFile>
#include <QTextStream>
#include <QRandomGenerator>
......@@ -7,11 +7,11 @@
#include <QDebug>
WordChooser::WordChooser(QObject *parent) : QObject(parent) {
MotusGame::MotusGame(QObject *parent) : QObject(parent) {
loadWords();
}
void WordChooser::loadWords() {
void MotusGame::loadWords() {
QFile file("Motus\\words_alpha.txt"); // ✅ fonctionne avec le .qrc
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
......@@ -27,7 +27,7 @@ void WordChooser::loadWords() {
}
}
QString WordChooser::getRandomWord() {
QString MotusGame::getRandomWord() {
if (words.isEmpty()) {
qDebug() << "❌ Aucune donnée chargée dans words.";
return "";
......
#ifndef WORDCHOOSER_H
#define WORDCHOOSER_H
#ifndef MOTUSGAME_H
#define MOTUSGAME_H
#include <QObject>
#include <QString>
#include <QStringList>
class WordChooser : public QObject {
class MotusGame : public QObject {
Q_OBJECT
public:
explicit WordChooser(QObject *parent = nullptr);
explicit MotusGame(QObject *parent = nullptr);
Q_INVOKABLE QString getRandomWord();
private:
......@@ -16,4 +16,4 @@ private:
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