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

On peut désormais changer le dictionnaire grâce aux boutons dédiés

parent 77e24f08
Branches
No related tags found
No related merge requests found
...@@ -42,6 +42,8 @@ qt_add_qml_module(appMotus ...@@ -42,6 +42,8 @@ qt_add_qml_module(appMotus
RESOURCES words_alpha.txt RESOURCES words_alpha.txt
RESOURCES words_alpha.txt RESOURCES words_alpha.txt
SOURCES motusgame.h motusgame.cpp SOURCES motusgame.h motusgame.cpp
RESOURCES mots_francais.txt
QML_FILES LangageButton.qml
) )
# 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.
......
import QtQuick
Item {
width: 200
height: 100
property alias _textText: _text.text
Rectangle {
id: rectangle
x: 0
y: 0
width: 200
height: 100
color: "#b43737"
Text {
id: _text
x: 0
y: 0
width: 200
height: 100
text: qsTr("Langage")
font.pixelSize: 30
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
}
...@@ -425,5 +425,51 @@ Window { ...@@ -425,5 +425,51 @@ Window {
source: "back_key.png" source: "back_key.png"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
Rectangle {
id: rectangle2
x: 312
y: 296
width: 265
height: 286
color: "#ffffff"
LangageButton {
id: langageButton
x: 33
y: 32
_textText: "Français"
MouseArea {
id: mouseArea2
x: 0
y: 0
width: 200
height: 100
onClicked: motusGame.dictionnaryChoosed="Motus\\mots_francais.txt"
}
}
LangageButton {
id: langageButton1
x: 33
y: 160
_textText: "English"
MouseArea {
id: mouseArea3
x: 0
y: 0
width: 200
height: 100
onClicked: motusGame.dictionnaryChoosed="Motus\\words_alpha.txt"
}
}
}
} }
} }
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -12,7 +12,8 @@ MotusGame::MotusGame(QObject *parent) : QObject(parent) { ...@@ -12,7 +12,8 @@ MotusGame::MotusGame(QObject *parent) : QObject(parent) {
} }
void MotusGame::loadWords() { void MotusGame::loadWords() {
QFile file("Motus\\words_alpha.txt"); // ✅ fonctionne avec le .qrc words.clear();
QFile file(dictionnaryChoosed); // ✅ fonctionne avec le .qrc
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file); QTextStream in(&file);
while (!in.atEnd()) { while (!in.atEnd()) {
...@@ -27,14 +28,27 @@ void MotusGame::loadWords() { ...@@ -27,14 +28,27 @@ void MotusGame::loadWords() {
} }
} }
QString MotusGame::getRandomWord() { QString MotusGame::getRandomWord() {
if (words.isEmpty()) { if (words.isEmpty())
qDebug() << "❌ Aucune donnée chargée dans words.";
return ""; return "";
}
int index = QRandomGenerator::global()->bounded(words.size()); int index = QRandomGenerator::global()->bounded(words.size());
QString mot = words[index]; motChoisi = words[index]; // <- ici on le stocke
qDebug() << "✅ Mot choisi :" << mot; return motChoisi;
return mot; }
QString MotusGame::getDictionnaryChoosed() const {
return dictionnaryChoosed;
} }
void MotusGame::setDictionnaryChoosed(const QString &value) {
if (dictionnaryChoosed != value) {
dictionnaryChoosed = value;
emit dictionnaryChoosedChanged(); // ✅ Signal pour que QML soit au courant
loadWords();
qDebug() << "📁 Nouveau dictionnaire sélectionné :" << dictionnaryChoosed;
}
}
...@@ -7,13 +7,32 @@ ...@@ -7,13 +7,32 @@
class MotusGame : public QObject { class MotusGame : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString dictionnaryChoosed
READ getDictionnaryChoosed
WRITE setDictionnaryChoosed
NOTIFY dictionnaryChoosedChanged)
public: public:
explicit MotusGame(QObject *parent = nullptr); explicit MotusGame(QObject *parent = nullptr);
Q_INVOKABLE QString getRandomWord(); Q_INVOKABLE QString getRandomWord();
QString getDictionnaryChoosed() const;
void setDictionnaryChoosed(const QString &value);
private: private:
QStringList words; QStringList words;
QString motChoisi; // Mot choisi aléatoirement dans la liste, selon le nombre de lettres choisi par l'utilisateur
int letterNumber=7; // Nombre de lettres dans le mot, choisi par l'utilisateur
int tryNumber=0; // Nombre d'essais effectués, si tryNumber = nombre max, c'est perdu
QString dictionnaryChoosed="Motus\\words_alpha.txt"; // "Motus\\words_alpha.txt" ou "Motus\\mots_francais.txt"
int Timer; // Chronomètre, s'il tombe à 0, c'est perdu
void loadWords(); void loadWords();
signals:
void dictionnaryChoosedChanged();
}; };
#endif // MOTUSGAME_H #endif // MOTUSGAME_H
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment