Quiz fonctionnel sans exception

This commit is contained in:
Montaigu-Lancelin Emilie 2026-01-09 10:13:55 +01:00
parent baa82893ad
commit 087c7902ee
6 changed files with 193 additions and 84 deletions

View file

@ -1,64 +1,47 @@
/*********************************************************************
* @file Apllication.cpp
* @author <mettre l'adresse mail ou nom prenom>
* @author Montaigu Emilie, Ouvrard Marine
* @brief Fichier source de l'application
*********************************************************************/
#include "Application.h"
#include <Wire.h>
#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);
}

View file

@ -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

View file

@ -1,60 +1,130 @@
#include "bdd.h"
#include "ecran.h"
#include "bouton.h"
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
#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<string> Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat){
int score = 0;
int questionNum = 0;
list<string>::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<string> listeQ;
list<string>::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<string> 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<<endl;
cout<<"Questions_Disney : "<<endl;
for(it=Questions_Disney.begin();it!=Questions_Disney.end();it++) {cout<<*it<<" ";cout<<endl;}
cout<<endl;*/
list<string> 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 : "<<endl;
for(it=Questions_Disney.begin();it!=Questions_Disney.end();it++) {cout<<*it<<" ";cout<<endl;}
*/
lcd.clear();
if (resultat == 1) {
lcd.print("Theme: Disney");
delay(2000);
play(lcd, Questions_Disney, reponses_disney, boutonRelief, boutonPlat);
} else {
lcd.print("Theme: Geographie");
delay(2000);
play(lcd, Questions_Geographie, reponses_geographie, boutonRelief, boutonPlat);
}
}

View file

@ -1,6 +1,11 @@
#ifndef bdd_H
#define bdd_H
#include "ecran.h"
void listequestions_init(ecran& lcd);
#include "bouton.h"
#include <list>
#include <string>
using namespace std;
void defileTexte(ecran &lcd, String texte);
void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat);
void play(ecran &lcd, list<string> Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat);
#endif

View file

@ -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;
}
}
/*
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;
};

View file

@ -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