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

Modification main.cpp et création classe Q_Object Jeu pour récupérer les infos...

Modification main.cpp et création classe Q_Object Jeu pour récupérer les infos du brain et pouvoir afficher le mot choisi
parent 0487091f
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ qt_add_qml_module(appmotus
QML_FILES Bouton.qml
RESOURCES
QML_FILES GameWindow.qml
SOURCES jeu.h jeu.cpp
)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
......
import QtQuick
Item {
......@@ -9,11 +12,38 @@ Item {
color: "#ffffff"
anchors.fill: parent
// Zone où le mot est affiché
Row {
id: motDisplay
spacing: 10
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 50
Repeater {
model: jeu.motAffiche.split(" ") // Divise la chaîne en lettres et "_"
Rectangle {
width: 50
height: 50
border.color: "#000000"
border.width: 2
radius: 5
color: "#eeeeee"
Text {
anchors.centerIn: parent
text: modelData
font.pixelSize: 20
}
}
}
}
Clavier {
id: clavier
x: 225
y: 594
}
}
}
#include "jeu.h"
#include <iostream>
Jeu::Jeu(QObject *parent) : QObject(parent), brain("./") {
brain.setFichierDico("words_alpha.txt");
brain.setNombreEssais(5);
brain.setTailleMots(5);
brain.initGame();
mot = QString::fromStdString(brain.getMot()); // ✅ Conversion std::string → QString
std::cout << "Mot choisi : " << mot.toStdString() << std::endl;
}
QString Jeu::getMotAffiche() {
if (mot.isEmpty()) return "";
QString affichage = QString(mot.at(0));
for (int i = 1; i < mot.length(); ++i) {
affichage += " _";
}
return affichage;
}
#ifndef JEU_H
#define JEU_H
#include <QObject>
#include "brain.h"
class Jeu : public QObject {
Q_OBJECT
Q_PROPERTY(QString motAffiche READ getMotAffiche NOTIFY motChanged)
public:
explicit Jeu(QObject *parent = nullptr);
QString getMotAffiche();
signals:
void motChanged();
private:
Brain brain;
QString mot;
};
#endif // JEU_H
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <iostream>
#include <QQmlContext>
#include "jeu.h"
#include "brain.h"
using namespace std;
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("motus", "Main");
Brain brain("./");
brain.setFichierDico("words_alpha.txt");
brain.setNombreEssais(5);
brain.setTailleMots(5);
brain.initGame();
cout << brain.getMot() << endl;
Jeu jeu;
engine.rootContext()->setContextProperty("jeu", &jeu);
engine.loadFromModule("motus", "Main");
return app.exec();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment