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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
void fonction_led(char* couleur, int position) { //a modifier avec le reel
if (position==0){
printf("( () () () )\n");
} else if (strcmp(couleur,"R")==0){
printf("( (R) () () )\n");
} else if (strcmp(couleur,"V")==0){
printf("( () (V) () )\n");
} else if (strcmp(couleur,"J")==0){
printf("( () () (J) )\n");
}
}
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("SIMON_STM32");
int etat_bouton_deux_joueurs = 0; //faire une correspondance au quatrieme bouton
int score = 0;
int deuxieme_joueur_joue = 0;
int score_un=0;
int score_deux=0;
char* suite_de_leds[100]={};
while (1) { //le programme tourne en continue
int etat_bouton_start = 1; //fiare correspondance bouton bleu de la carte
int perdu = 0;
if (etat_bouton_start){ //a changer...
affiche_lcd("LET'S GO !");
if (etat_bouton_deux_joueurs && !deuxieme_joueur_joue){
affiche_lcd("MODE 2J");
affiche_lcd("J1!");
}
else if (!etat_bouton_deux_joueurs && !deuxieme_joueur_joue) {
affiche_lcd("MODE 1J");
}
while (perdu!= 1) { //ici on lance un niveau
suite_de_leds[score] = choix_aleatoire();
score++;
for (int i = 0; i<score; i++){
fonction_led(suite_de_leds[i], 1); //on
fonction_led(suite_de_leds[i], 0); //off
sleep(1);
}
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("SCORE :");
char score_char[10];
sprintf(score_char, "%d", score-1);
affiche_lcd(score_char);
perdu = 1;
etat_bouton_start=0;
} else {
// affiche_lcd("BRAVO !");
perdu = 0;
}
j++;
} while (j<score && perdu!=1);
//tant qu'on a des leds a faire allume et qu'on a pas perdu
}
if (etat_bouton_deux_joueurs && perdu==1 && !deuxieme_joueur_joue){
affiche_lcd("J2!");
etat_bouton_deux_joueurs = 0;
perdu = 0;
etat_bouton_start=1;
score_un = score;
deuxieme_joueur_joue = 1;
} else if (deuxieme_joueur_joue){
score_deux = score;
if (score_un>score_deux){affiche_lcd("JOUEUR 1 GAGNE!");}
else if (score_un<score_deux){affiche_lcd("JOUEUR 2 GAGNE!");}
else {affiche_lcd("EGALITE...");}
}
}
score=0;
}
return 0;
}
|