130 lines
No EOL
3.5 KiB
C++
130 lines
No EOL
3.5 KiB
C++
#include "bdd.h"
|
|
#include "ecran.h"
|
|
#include "bouton.h"
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <string>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
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(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);
|
|
|
|
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 ?");
|
|
|
|
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 ?");
|
|
|
|
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);
|
|
}
|
|
|
|
} |