blob: 2b3ed838f8fd33db8aeaa9e133de2a0f32c49b1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
void fonction_led(char* couleur, int position) { //a modifier avec le reel
printf("(La led %s se met en position %d.)\n", couleur, position);
}
void affiche_lcd(char* contenu) { //a modifier par l'utlisation des lib
printf ("[LCD : %s]\n", contenu);
}
char* choix_aleatoire(void) { //fonctionne
char* couleur_leds[3]={"R","V","J"}; //nos led
srand(time(0));
int aleatoire = (rand() % (2 - 0 + 1)) + 0; //choix entre 0 et 2
char* choix = couleur_leds[aleatoire];
return choix;
}
int main(void) {
affiche_lcd("Bienvenue sur SIMON_STM32");
int etat_bouton_start = 1; //a changer en fonction des pins et tout
int niveau = 0;
char* suite_de_leds[100];
int perdu = 0;
int tour=0;
while (tour<10 && perdu!= 1) {
if (etat_bouton_start){//a changer...
affiche_lcd("Let's go !");
suite_de_leds[niveau] = choix_aleatoire();
niveau++;
for (int i = 0; i<niveau; i++){
fonction_led(suite_de_leds[i], 1);
fonction_led(suite_de_leds[i], 0);
}
affiche_lcd("A vous !");
int j=0;
do {
char bouton[100];
scanf("%s", bouton); //a remplacer par la reception IRL du bouton
char* bouton_couleur = bouton; //pareil
if (*bouton_couleur!=*suite_de_leds[j]){
affiche_lcd("GAME OVER !");
affiche_lcd("Niveau atteind :");
char niveau_char[10];
sprintf(niveau_char, "%d", niveau);
affiche_lcd(niveau_char);
perdu = 1;
} else {
affiche_lcd("BRAVO !");
perdu = 0;
}
j++;
} while (j<niveau && perdu!=1);
//tant qu'on a des leds a faire allume et qu'on a pas perdu
}
tour++;
}
return 0;
}
|