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

Le timer marche finalement !

parent 419dd3c9
Branches
No related tags found
No related merge requests found
...@@ -44,6 +44,8 @@ qt_add_qml_module(appMotus ...@@ -44,6 +44,8 @@ qt_add_qml_module(appMotus
SOURCES motusgame.h motusgame.cpp SOURCES motusgame.h motusgame.cpp
RESOURCES mots_francais.txt RESOURCES mots_francais.txt
QML_FILES LangageButton.qml QML_FILES LangageButton.qml
QML_FILES
QML_FILES MotusTimer.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.
......
...@@ -410,6 +410,7 @@ Window { ...@@ -410,6 +410,7 @@ Window {
onClicked: { onClicked: {
let mot = motusGame.getRandomWord(); let mot = motusGame.getRandomWord();
console.log("Mot choisi :", mot); console.log("Mot choisi :", mot);
motusGame.startTimer(); // 🕒 démarre le chrono
case3._textText = mot; case3._textText = mot;
onClicked: case3._textColor="#51c3e1"; onClicked: case3._textColor="#51c3e1";
} }
...@@ -471,5 +472,11 @@ Window { ...@@ -471,5 +472,11 @@ Window {
} }
} }
MotusTimer {
id: motusTimer
x: 502
y: 73
}
} }
} }
import QtQuick
Item {
width: 150
height: 75
Rectangle {
id: rectangle
width: 150
height: 75
color: {
if (!motusGame) return "#6ceacb";
return motusGame.remainingTime <= 20 ? "#e86161" : "#6ceacb"; // rouge si <= 20s
}
Text {
id: _text
width: 150
height: 75
text: {
if (!motusGame) return "";
let minutes = Math.floor(motusGame.remainingTime / 60);
let seconds = motusGame.remainingTime % 60;
return minutes + "m " + (seconds < 10 ? "0" + seconds : seconds) + "s";
}
font.pixelSize: 40
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: "black"
}
}
}
...@@ -9,7 +9,34 @@ ...@@ -9,7 +9,34 @@
MotusGame::MotusGame(QObject *parent) : QObject(parent) { MotusGame::MotusGame(QObject *parent) : QObject(parent) {
loadWords(); loadWords();
qDebug() << "🔧 Connexion timer établie";
countdownTimer = new QTimer(this); // ✅ rattaché à this
countdownTimer->setInterval(1000);
connect(countdownTimer, &QTimer::timeout, this, [this]() {
qDebug() << "🔁 Timeout déclenché";
if (remainingTime > 0) {
remainingTime--;
emit timerUpdated();
qDebug() << "⏱️ Tick:" << remainingTime;
if (remainingTime == 0) {
countdownTimer->stop();
qDebug() << "⏱️ Temps écoulé !";
}
} }
});
qDebug() << "🔧 Connexion timer établie";
}
void MotusGame::loadWords() { void MotusGame::loadWords() {
words.clear(); words.clear();
...@@ -52,3 +79,24 @@ void MotusGame::setDictionnaryChoosed(const QString &value) { ...@@ -52,3 +79,24 @@ void MotusGame::setDictionnaryChoosed(const QString &value) {
qDebug() << "📁 Nouveau dictionnaire sélectionné :" << dictionnaryChoosed; qDebug() << "📁 Nouveau dictionnaire sélectionné :" << dictionnaryChoosed;
} }
} }
void MotusGame::startTimer() {
qDebug() << "🔁 startTimer() appelé";
remainingTime = 120;
emit timerUpdated();
countdownTimer->stop();
countdownTimer->start();
qDebug() << "▶️ Timer actif ?" << countdownTimer->isActive();
qDebug() << "▶️ Timer lancé";
qDebug() << "⏳ remainingTime =" << remainingTime;
}
int MotusGame::getRemainingTime() const {
return remainingTime;
}
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTimer>
class MotusGame : public QObject { class MotusGame : public QObject {
Q_OBJECT Q_OBJECT
...@@ -13,6 +15,8 @@ class MotusGame : public QObject { ...@@ -13,6 +15,8 @@ class MotusGame : public QObject {
WRITE setDictionnaryChoosed WRITE setDictionnaryChoosed
NOTIFY dictionnaryChoosedChanged) NOTIFY dictionnaryChoosedChanged)
Q_PROPERTY(int remainingTime READ getRemainingTime NOTIFY timerUpdated)
public: public:
explicit MotusGame(QObject *parent = nullptr); explicit MotusGame(QObject *parent = nullptr);
Q_INVOKABLE QString getRandomWord(); Q_INVOKABLE QString getRandomWord();
...@@ -20,6 +24,11 @@ public: ...@@ -20,6 +24,11 @@ public:
QString getDictionnaryChoosed() const; QString getDictionnaryChoosed() const;
void setDictionnaryChoosed(const QString &value); void setDictionnaryChoosed(const QString &value);
Q_INVOKABLE void startTimer();
int getRemainingTime() const;
private: private:
QStringList words; QStringList words;
...@@ -27,12 +36,21 @@ private: ...@@ -27,12 +36,21 @@ private:
int letterNumber=7; // Nombre de lettres dans le mot, 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 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" 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
QTimer *countdownTimer;
int remainingTime = 120; // chrono en secondes
void loadWords(); void loadWords();
signals: signals:
void dictionnaryChoosedChanged(); void dictionnaryChoosedChanged();
void timerUpdated();
}; };
#endif // MOTUSGAME_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