From 087c7902ee39d1a4e064ad78c2c917f1095619a2 Mon Sep 17 00:00:00 2001 From: Montaigu-Lancelin Emilie Date: Fri, 9 Jan 2026 10:13:55 +0100 Subject: [PATCH] Quiz fonctionnel sans exception --- BE c/projet/Application.cpp | 67 +++++++------------ BE c/projet/Application.h | 12 +++- BE c/projet/bdd.cpp | 130 +++++++++++++++++++++++++++--------- BE c/projet/bdd.h | 9 ++- BE c/projet/bouton.cpp | 53 +++++++++++++-- BE c/projet/bouton.h | 6 +- 6 files changed, 193 insertions(+), 84 deletions(-) diff --git a/BE c/projet/Application.cpp b/BE c/projet/Application.cpp index 5d6ae22..b179f46 100644 --- a/BE c/projet/Application.cpp +++ b/BE c/projet/Application.cpp @@ -1,64 +1,47 @@ /********************************************************************* * @file Apllication.cpp - * @author + * @author Montaigu Emilie, Ouvrard Marine * @brief Fichier source de l'application *********************************************************************/ #include "Application.h" #include #include "rgb_lcd.h" #include "ecran.h" - #include "bdd.h" - #include "bouton.h" -const int buttonPin = D8; // the number of the pushbutton pin -const int ledPin = D7; // the number of the LED pin -int buttonState = 0; -ecran lcd; +#include "bdd.h" +#include "bouton.h" +#define buttonPinRelief D8 +#define buttonPinPlat D6 +Application::Application(): ledPin(D7), colorR(255), colorG(100), colorB(100), boutonRelief(buttonPinRelief), boutonPlat(buttonPinPlat) {} - -const int colorR = 255; -const int colorG = 100; -const int colorB = 100; -Application::Application() -{ - // Code - ; -} - Application::~Application() { - // Code - ; + /*if (boutonRelief != nullptr) { + delete boutonRelief; + } + if (boutonPlat != nullptr) { + delete boutonPlat; + }*/ } void Application::init(void) { - pinMode(ledPin, OUTPUT); - pinMode(buttonPin, INPUT); - bouton Bouton1(buttonPin); - - // set up the LCD's number of columns and rows: - lcd.begin(32, 16); - - lcd.setRGB(colorR, colorG, colorB); - - // Print a message to the LCD. - lcd.print("On commence a jouer?"); - - delay(1000); - listequestions_init(lcd); - + Serial.begin(115200); + lcd.begin(32, 16); + lcd.setRGB(colorR, colorG, colorB); + pinMode(ledPin, OUTPUT); + pinMode(buttonPinRelief, INPUT); + pinMode(buttonPinPlat, INPUT); + delay(1500); + Serial.println("A"); } void Application::run(void) { - - // set the cursor to column 0, line 1 - // (note: line 1 is the second row, since counting begins with 0): - //lcd.setCursor(0, 1); - // print the number of seconds since reset: - //lcd.print(millis() / 1000); - - delay(100); + lcd.clear(); + lcd.print("On commence a jouer?"); + delay(1500); + listequestions_init(lcd, boutonRelief, boutonPlat); + delay(100); } \ No newline at end of file diff --git a/BE c/projet/Application.h b/BE c/projet/Application.h index fee39a3..f59526e 100644 --- a/BE c/projet/Application.h +++ b/BE c/projet/Application.h @@ -5,7 +5,10 @@ *********************************************************************/ #ifndef APPLICATION_H_ #define APPLICATION_H_ - +#include "rgb_lcd.h" +#include "ecran.h" + #include "bdd.h" + #include "bouton.h" /** * @class Application * @brief Classe Application @@ -13,6 +16,13 @@ class Application { public : + const int ledPin; + const int colorR; + const int colorG; + const int colorB; + ecran lcd; + bouton boutonRelief; + bouton boutonPlat; /** * @fn Application(); * @brief Constructeur par defaut diff --git a/BE c/projet/bdd.cpp b/BE c/projet/bdd.cpp index da01844..c2a6f2c 100644 --- a/BE c/projet/bdd.cpp +++ b/BE c/projet/bdd.cpp @@ -1,60 +1,130 @@ #include "bdd.h" #include "ecran.h" - +#include "bouton.h" #include #include +#include #include -#include "string.h" using namespace std; -void listequestions_init(ecran& lcd){ +int reponses_disney[] = {0, 1, 0}; +int reponses_geographie[] = {0, 1, 1}; +void defileTexte(ecran &lcd, String texte) { + int largeur = 32; + texte += " "; + int longueur = texte.length(); + int pos = 0; + + while (pos <= longueur - largeur) { + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(texte.substring(pos, pos + largeur)); + delay(400); + pos++; + } +} +void play(ecran &lcd, list Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat){ + int score = 0; + int questionNum = 0; + list::iterator it; + + // Parcourir toutes les questions + for(it = Questions.begin(); it != Questions.end(); it++) { + lcd.clear(); + + // Afficher le numéro de la question + lcd.setCursor(0, 0); + lcd.print("Q"); + lcd.print(questionNum + 1); + lcd.print(": "); + delay(1000); + + + lcd.clear(); + + defileTexte(lcd, (*it).c_str()); + delay(1500); + + + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Relief=Vrai"); + lcd.setCursor(0, 1); + lcd.print("Plat=Faux"); + delay(1000); + + // Attendre la réponse de l'utilisateur + bool reponseUtilisateur = choix_bouton(boutonRelief, boutonPlat); + + // Vérifier la réponse (1 pour boutonRelief/Vrai, 0 pour boutonPlat/Faux) + if (reponseUtilisateur == reponses[questionNum]) { + lcd.clear(); + lcd.print("Correct !"); + score++; + } else { + lcd.clear(); + lcd.print("Faux !"); + } + delay(2000); + + questionNum++; + } + + // Afficher le score final + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Score: "); + lcd.print(score); + lcd.print("/"); + lcd.print(questionNum); + lcd.setCursor(0, 1); + lcd.print("Bravo !"); + delay(5000); +} + + +void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat){ list listeQ; list::iterator it; listeQ.push_back("1 Disney"); listeQ.push_back("2 Geographie"); lcd.clear(); lcd.print("Thematiques : "); - delay(3000); + delay(1000); lcd.clear(); int nbT=0; for(it=listeQ.begin();it!=listeQ.end();it++) { - lcd.setCursor(0, nbT++); lcd.print((*it).c_str()); - + } + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Relief=Disney"); + lcd.setCursor(0, 1); + lcd.print("Plat=Geographie"); + delay(1000); - }//cout<<*it<<" "; - delay(5000); + bool resultat = choix_bouton(boutonRelief, boutonPlat); list Questions_Disney; Questions_Disney.push_back("Patrick est le nom du cameleon de Raiponce ?"); Questions_Disney.push_back("La robe de Tiana est verte ?"); Questions_Disney.push_back("Cendrillon etait le premier disney ?"); - for(it=Questions_Disney.begin();it!=Questions_Disney.end();it++) { - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print((*it).c_str()); - - // Fait défiler le texte vers la gauche - for(int i = 0; i < (*it).length(); i++) { - lcd.scrollDisplayLeft(); - delay(300); - } - delay(2000); - - } - - /*cout< Questions_Geographie; Questions_Geographie.push_back("Rio de Janeiro est la capitale du Bresil ?"); Questions_Geographie.push_back("L'Inde est le pays le plus peuple ?"); Questions_Geographie.push_back("Les Pyrenees Atlantiques ont 64 en numéro de département ?"); - /*cout<<"Questions_Géographie : "< +#include +using namespace std; +void defileTexte(ecran &lcd, String texte); +void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat); +void play(ecran &lcd, list Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat); #endif \ No newline at end of file diff --git a/BE c/projet/bouton.cpp b/BE c/projet/bouton.cpp index 6e31cf9..99365b0 100644 --- a/BE c/projet/bouton.cpp +++ b/BE c/projet/bouton.cpp @@ -1,12 +1,51 @@ #include "bouton.h" - +#include "rgb_lcd.h" bouton:: bouton() :capteur(),etat(0){} bouton::bouton(int pin) : capteur(pin), etat(0) {} -bool bouton::lire_etat(bouton& B){ -bool res; -int buttonState = digitalRead(B.getpin()); - if (buttonState == HIGH) res=1; - else res=0; +bool bouton::lire_etat(){ + bool res; + int buttonState = digitalRead(this->getpin()); + if (buttonState == HIGH) res=1; + else res=0; return res; -} \ No newline at end of file +} + +/* +Renvoie 1 si bouton relief et renvoie 0 si bouton plat +*/ +bool choix_bouton(bouton &Brelief,bouton &Bplat){ + + Serial.println("A"); + + while (Brelief.lire_etat() == 1 || Bplat.lire_etat() == 1) { + delay(10); + } + + Serial.println("A"); + + while (Brelief.lire_etat() == 0 && Bplat.lire_etat() == 0) { + delay(10); + } + + bool reliefPresse = Brelief.lire_etat(); + bool platPresse = Bplat.lire_etat(); + + Serial.println("A"); + + if (reliefPresse) { + Serial.println("A"); + while (Brelief.lire_etat() == 1) { + delay(10); + } + return 1; + } + else if (platPresse) { + Serial.println("A"); + while (Bplat.lire_etat() == 1) { + delay(10); + } + return 0; + } + return 0; +}; \ No newline at end of file diff --git a/BE c/projet/bouton.h b/BE c/projet/bouton.h index 35edd47..9a969e1 100644 --- a/BE c/projet/bouton.h +++ b/BE c/projet/bouton.h @@ -1,14 +1,16 @@ #ifndef bouton_H #define bouton_H #include "capteur.h" +#include "rgb_lcd.h" class bouton : public capteur { private: bool etat; public: bouton(); bouton(int pin); - bool lire_etat(bouton& B); + bool lire_etat(); + }; - +bool choix_bouton(bouton &Brelief,bouton &Bplat); #endif \ No newline at end of file