summaryrefslogtreecommitdiff
path: root/prototype_simon.c
diff options
context:
space:
mode:
Diffstat (limited to 'prototype_simon.c')
-rw-r--r--prototype_simon.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/prototype_simon.c b/prototype_simon.c
new file mode 100644
index 0000000..2b3ed83
--- /dev/null
+++ b/prototype_simon.c
@@ -0,0 +1,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;
+}