Advertisement
tapette101

Plantamiz - Version 2.0

Jun 7th, 2015
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <time.h>
  6. #include <windows.h>
  7.  
  8. /*TODO:  sauvegarde de fichier*/
  9.  
  10. typedef struct Level{   //structure qui regroupe les points gagnés, le but de points, le nombre de coups autorisés et le nb de coups utilisés
  11.     char ** tableau[20][40];
  12.     int pointS;
  13.     int pointF;
  14.     int pointP;
  15.     int pointO;
  16.     int pointM;
  17.     int goalS;
  18.     int goalF;
  19.     int goalP;
  20.     int goalO;
  21.     int goalM;
  22.     int allowedMoves;
  23.     int * usedMoves;
  24.  
  25. }t_level;
  26.  
  27. //tous les éléments musicaux sont dans ce bloc
  28. int music(int pitch, int length, int time){//renvoie une fréquence (pitch) qui dure une longueur (length) et pause le systeme pendant
  29. Beep(pitch, length);
  30. Sleep(time);
  31. return(0);
  32. }
  33.  
  34. void soundMove(){music(440, 100, 1);}
  35. void soundSelect(){music(200,100,1);}
  36. void soundAfterMove(){music(600,100,1);}
  37. void GameOverSound(){music(375, 500, 0);music(300, 500,0);music(200, 500, 0);}
  38. void WelcomeSound(){music(200, 500, 0);music(300, 500,0);music(400, 500, 0);}
  39. void DingSound(){music(700,150,1);}
  40. void WonSound(){music(300, 400, 0);music(300, 250,0);music(400, 700, 0);}
  41.  
  42. //fonction qui va permettre de compter le nombre de points gagnés par fruit/légume
  43. void verification(char tab[20][40], t_level unNiveau, int point[5]){ //fonction qui va permettre de compter le nombre de points gagnés par fruit/légume
  44.     int a=0; //nous permet de savoir si on a une ligne de 5 ou non
  45.     int i, j, k, l, n=0, m;
  46.     char temp;
  47.     for(i=0;i<20;i++){
  48.         for(j=0;j<40;j++){
  49.             if(tab[i][j]!='.'){
  50.             while(nothingToSuppr(tab)==0){       //boucle infinie qui ne se termine qu'une fois les tests effectués
  51.                                 //on commence par tester les 5== de suite en ligne et en colonne
  52.                 if((tab[i][j]!='.')&&((tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j] && tab[i][j]==tab[i+3][j] && tab[i][j]==tab[i+4][j]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2] && tab[i][j]==tab[i][j+3] && tab[i][j]==tab[i][j+4]))){
  53.                     temp=tab[i][j];
  54.                     for (k=0;k<20;k++){
  55.                         for(l=0;l<40;l++){
  56.                             if(tab[k][l]==temp){n++;deleteCase(tab,k,l);}       //ici, on cherche toutes les cases du tableau de même lettre que les 5 identiques
  57.                         }
  58.                     }
  59.                     if(temp=='S'){point[0]+=n;}
  60.                     if(temp=='F'){point[1]+=n;}
  61.                     if(temp=='P'){point[2]+=n;}
  62.                     if(temp=='O'){point[3]+=n;}
  63.                     if(temp=='M'){point[4]+=n;}
  64.                     break;       //bien noter la fonction break ici qui permet au while(1) de ne pas tourner à l'infini !
  65.                 }               //puis les 4== en colonne
  66.                 else if((tab[i][j]!='.')&&(tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j] && tab[i][j]==tab[i+3][j])){
  67.                     if(tab[i][j]=='S') {point[0]+=8;}
  68.                     if(tab[i][j]=='F') {point[1]+=8;}
  69.                     if(tab[i][j]=='P') {point[2]+=8;}
  70.                     if(tab[i][j]=='O') {point[3]+=8;}
  71.                     if(tab[i][j]=='M') {point[4]+=8;}
  72.                     for(m=0;m<4;m++){//on teste sur chaque case si il y en a deux sur les cotés (croix et L)
  73.                     if(tab[i+m][j-2]==tab[i+m][j-1] && tab[i+m][j-1]==tab[i+m][j]){
  74.                         if(tab[i][j]=='S') {point[0]+=6;}
  75.                         if(tab[i][j]=='F') {point[1]+=6;}
  76.                         if(tab[i][j]=='P') {point[2]+=6;}
  77.                         if(tab[i][j]=='O') {point[3]+=6;}
  78.                         if(tab[i][j]=='M') {point[4]+=6;}
  79.                         deleteCase(tab,i+m,j-2);deleteCase(tab,i+m,j-1);}
  80.                     if(tab[i+m][j-1]==tab[i+m][j+1] && tab[i+m][j-1]==tab[i+m][j]){
  81.                         if(tab[i][j]=='S') {point[0]+=6;}
  82.                         if(tab[i][j]=='F') {point[1]+=6;}
  83.                         if(tab[i][j]=='P') {point[2]+=6;}
  84.                         if(tab[i][j]=='O') {point[3]+=6;}
  85.                         if(tab[i][j]=='M') {point[4]+=6;}
  86.                         deleteCase(tab,i+m,j-1);deleteCase(tab,i+m,j+1);}
  87.                     if(tab[i+m][j+1]==tab[i+m][j+2] && tab[i+m][j+1]==tab[i+m][j]){
  88.                         if(tab[i][j]=='S') {point[0]+=6;}
  89.                         if(tab[i][j]=='F') {point[1]+=6;}
  90.                         if(tab[i][j]=='P') {point[2]+=6;}
  91.                         if(tab[i][j]=='O') {point[3]+=6;}
  92.                         if(tab[i][j]=='M') {point[4]+=6;}
  93.                         deleteCase(tab,i+m,j+1);deleteCase(tab,i+m,j+2);}
  94.                     }
  95.                     deleteCase(tab,i,j);deleteCase(tab,i+1,j);deleteCase(tab,i+2,j);deleteCase(tab,i+3,j);
  96.  
  97.                     break;
  98.                 }               //maintenant, les 4== en ligne
  99.                 else if((tab[i][j]!='.')&&(tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2] && tab[i][j]==tab[i][j+3])){
  100.                     if(tab[i][j]=='S') {point[0]+=8;}
  101.                     if(tab[i][j]=='F') {point[1]+=8;}
  102.                     if(tab[i][j]=='P') {point[2]+=8;}
  103.                     if(tab[i][j]=='O') {point[3]+=8;}
  104.                     if(tab[i][j]=='M') {point[4]+=8;}
  105.                     for(m=0;m<4;m++){//on teste sur chaque case si il y en a deux sur les cotés (croix et L)
  106.                     if(tab[i-2][j+m]==tab[i-1][j+m] && tab[i-1][j+m]==tab[i][j+m]){
  107.                         if(tab[i][j]=='S') {point[0]+=6;}
  108.                         if(tab[i][j]=='F') {point[1]+=6;}
  109.                         if(tab[i][j]=='P') {point[2]+=6;}
  110.                         if(tab[i][j]=='O') {point[3]+=6;}
  111.                         if(tab[i][j]=='M') {point[4]+=6;}
  112.                         deleteCase(tab,i-1,j+m);deleteCase(tab,i-2,j+m);}
  113.                     if(tab[i-1][j+m]==tab[i+1][j+m] && tab[i+1][j+m]==tab[i][j+m]){
  114.                         if(tab[i][j]=='S') {point[0]+=6;}
  115.                         if(tab[i][j]=='F') {point[1]+=6;}
  116.                         if(tab[i][j]=='P') {point[2]+=6;}
  117.                         if(tab[i][j]=='O') {point[3]+=6;}
  118.                         if(tab[i][j]=='M') {point[4]+=6;}
  119.                         deleteCase(tab,i-1,j+m);deleteCase(tab,i+1,j+m);}
  120.                     if(tab[i+1][j+m]==tab[i+2][j+m] && tab[i+1][j+m]==tab[i][j+m]){
  121.                         if(tab[i][j]=='S') {point[0]+=6;}
  122.                         if(tab[i][j]=='F') {point[1]+=6;}
  123.                         if(tab[i][j]=='P') {point[2]+=6;}
  124.                         if(tab[i][j]=='O') {point[3]+=6;}
  125.                         if(tab[i][j]=='M') {point[4]+=6;}
  126.                         deleteCase(tab,i+1,j+m);deleteCase(tab,i+2,j+m);}
  127.                     }
  128.                     deleteCase(tab,i,j);deleteCase(tab,i,j+1);deleteCase(tab,i,j+2);deleteCase(tab,i,j+3);
  129.  
  130.                     break;
  131.                 }               //et enfin les 3== en colonne
  132.                 else if((tab[i][j]!='.')&&(tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j])){
  133.                     if(tab[i][j]=='S') {point[0]+=3;}
  134.                     if(tab[i][j]=='F') {point[1]+=3;}
  135.                     if(tab[i][j]=='P') {point[2]+=3;}
  136.                     if(tab[i][j]=='O') {point[3]+=3;}
  137.                     if(tab[i][j]=='M') {point[4]+=3;}
  138.                     for(m=0;m<3;m++){//on teste sur chaque case si il y en a deux sur les cotés (croix et L)
  139.                     if(tab[i+m][j-2]==tab[i+m][j-1] && tab[i+m][j-1]==tab[i+m][j]){
  140.                         if(tab[i][j]=='S') {point[0]+=9;}
  141.                         if(tab[i][j]=='F') {point[1]+=9;}
  142.                         if(tab[i][j]=='P') {point[2]+=9;}
  143.                         if(tab[i][j]=='O') {point[3]+=9;}
  144.                         if(tab[i][j]=='M') {point[4]+=9;}
  145.                         deleteCase(tab,i+m,j-2);deleteCase(tab,i+m,j-1);}
  146.                     if(tab[i+m][j-1]==tab[i+m][j+1] && tab[i+m][j-1]==tab[i+m][j]){
  147.                         if(tab[i][j]=='S') {point[0]+=9;}
  148.                         if(tab[i][j]=='F') {point[1]+=9;}
  149.                         if(tab[i][j]=='P') {point[2]+=9;}
  150.                         if(tab[i][j]=='O') {point[3]+=9;}
  151.                         if(tab[i][j]=='M') {point[4]+=9;}
  152.                         deleteCase(tab,i+m,j-1);deleteCase(tab,i+m,j+1);}
  153.                     if(tab[i+m][j+1]==tab[i+m][j+2] && tab[i+m][j+1]==tab[i+m][j]){
  154.                         if(tab[i][j]=='S') {point[0]+=9;}
  155.                         if(tab[i][j]=='F') {point[1]+=9;}
  156.                         if(tab[i][j]=='P') {point[2]+=9;}
  157.                         if(tab[i][j]=='O') {point[3]+=9;}
  158.                         if(tab[i][j]=='M') {point[4]+=9;}
  159.                         deleteCase(tab,i+m,j+2);deleteCase(tab,i+m,j+1);}
  160.                     }
  161.                     deleteCase(tab,i,j);deleteCase(tab,i+1,j);deleteCase(tab,i+2,j);
  162.  
  163.                     break;
  164.                 }              //au tour des 3== en ligne
  165.                 else if((tab[i][j]!='.')&&(tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2])){
  166.                     if(tab[i][j]=='S') {point[0]+=3;}
  167.                     if(tab[i][j]=='F') {point[1]+=3;}
  168.                     if(tab[i][j]=='P') {point[2]+=3;}
  169.                     if(tab[i][j]=='O') {point[3]+=3;}
  170.                     if(tab[i][j]=='M') {point[4]+=3;}
  171.                     for(m=0;m<3;m++){//on teste sur chaque case si il y en a deux sur les cotés (croix et L)
  172.                     if(tab[i-2][j+m]==tab[i-1][j+m] && tab[i-1][j+m]==tab[i][j+m]){
  173.                         if(tab[i][j]=='S') {point[0]+=9;}
  174.                         if(tab[i][j]=='F') {point[1]+=9;}
  175.                         if(tab[i][j]=='P') {point[2]+=9;}
  176.                         if(tab[i][j]=='O') {point[3]+=9;}
  177.                         if(tab[i][j]=='M') {point[4]+=9;}
  178.                         deleteCase(tab,i-1,j+m);deleteCase(tab,i-2,j+m);}
  179.                     if(tab[i-1][j+m]==tab[i+1][j+m] && tab[i+1][j+m]==tab[i][j+m]){
  180.                         if(tab[i][j]=='S') {point[0]+=9;}
  181.                         if(tab[i][j]=='F') {point[1]+=9;}
  182.                         if(tab[i][j]=='P') {point[2]+=9;}
  183.                         if(tab[i][j]=='O') {point[3]+=9;}
  184.                         if(tab[i][j]=='M') {point[4]+=9;}
  185.                         deleteCase(tab,i-1,j+m);deleteCase(tab,i+1,j+m);}
  186.                     if(tab[i+1][j+m]==tab[i+2][j+m] && tab[i+1][j+m]==tab[i][j+m]){
  187.                         if(tab[i][j]=='S') {point[0]+=9;}
  188.                         if(tab[i][j]=='F') {point[1]+=9;}
  189.                         if(tab[i][j]=='P') {point[2]+=9;}
  190.                         if(tab[i][j]=='O') {point[3]+=9;}
  191.                         if(tab[i][j]=='M') {point[4]+=9;}
  192.                         deleteCase(tab,i+1,j+m);deleteCase(tab,i+2,j+m);}
  193.                     }
  194.                     deleteCase(tab,i,j);deleteCase(tab,i,j+1);deleteCase(tab,i,j+2);
  195.  
  196.                     break;
  197.                 }
  198.                 else break; //dans TOUS les cas, il y aura un break qui permettre de sortir du while(1)
  199.             }//fin de la boucle infinie while(1)
  200.  
  201.             }
  202.         }
  203.     }
  204.     //affichage des points
  205.     gotoligcol(7,90);color(3,0);printf("\t\t Score : ");color(15,0);
  206.     gotoligcol(9,90);if(point[0]>=unNiveau.goalS){color(0,2);}else{color(2,0);}printf("\t    Points S : %d / %d \t\t", point[0], unNiveau.goalS);gotoligcol(9,128);color(15,0);printf("\t\t");
  207.     gotoligcol(10,90);if(point[1]>=unNiveau.goalF){color(0,2);}else{color(2,0);}printf("\t    Points F : %d / %d \t\t", point[1], unNiveau.goalF);gotoligcol(10,128);color(15,0);printf("\t\t");
  208.     gotoligcol(11,90);if(point[2]>=unNiveau.goalP){color(0,2);}else{color(2,0);}printf("\t    Points P : %d / %d \t\t", point[2], unNiveau.goalP);gotoligcol(11,128);color(15,0);printf("\t\t");
  209.     gotoligcol(12,90);if(point[3]>=unNiveau.goalO){color(0,2);}else{color(2,0);}printf("\t    Points O : %d / %d \t\t", point[3], unNiveau.goalO);gotoligcol(12,128);color(15,0);printf("\t\t");
  210.     gotoligcol(13,90);if(point[4]>=unNiveau.goalM){color(0,2);}else{color(2,0);}printf("\t    Points M : %d / %d \t\t", point[4], unNiveau.goalM);gotoligcol(13,128);color(15,0);printf("\t\t");
  211.  
  212. }
  213.  
  214.  
  215. int ligneDeCinq(char tab[20][40]){ //permet d'utiliser refill au lieu de refill2 lorsqu'on à une suite de 5 lettres (sinon le jeu tourne pendant 10 min...)
  216.     int i, j, a=0;
  217.     for(i=0; i<20; i++){
  218.         for(j=0;j<40;j++){
  219.             if((tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j] && tab[i][j]==tab[i+3][j] && tab[i][j]==tab[i+4][j]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2] && tab[i][j]==tab[i][j+3] && tab[i][j]==tab[i][j+4])){
  220.                 a=1;
  221.             }
  222.         }
  223.  
  224.     }
  225.     return a;
  226. }
  227.  
  228. int nothingToSuppr(char tab[20][40]){//fonction qui vérifie dans un tableau et rend 0 si il y a des séries de 3 lettres identiques, 1 sinon.
  229.     int a = 1; int i, j;
  230.     for(i=0; i<20; i++){
  231.         for(j=0; j<40; j++){
  232.  
  233.             if((tab[i][j]!='.') && ((tab[i][j]==tab[i+1][j] && tab[i][j]==tab[i+2][j]) || (tab[i][j]==tab[i][j+1] && tab[i][j]==tab[i][j+2]))){a=0;}
  234.         }
  235.     }
  236.     return a;
  237.  
  238. }
  239.  
  240. void color(int t,int f){//fonction pour la couleur
  241.         HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
  242.             SetConsoleTextAttribute(H,f*16+t);
  243. }
  244.  
  245. void gotoligcol( int lig, int col){//gotoligcol déplace le curseur à la ligne et colonne voulue
  246.   COORD mycoord;
  247.   mycoord.X = col;
  248.   mycoord.Y = lig;
  249.   SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), mycoord );
  250. }
  251.  
  252. void echangercoo(int lig,int col, int i, int j, char tab[20][40])
  253. {   //permet de changer les coordonnées de deux lettres côte à côte
  254.  
  255.   char X;
  256.   char temp;
  257.   X=getch();
  258.   switch (X)
  259.     {
  260.     case 's':
  261.       if (lig<40){gotoligcol(lig,col);
  262.       temp=tab[i][j];
  263.       tab[i][j]=tab[i+1][j];
  264.       tab[i+1][j]=temp;
  265.       gotoligcol(0,0);
  266.       affichage(tab);}else{gotoligcol(0,0);affichage(tab);}
  267.       soundAfterMove();
  268.       break;
  269.  
  270.     case 'a':
  271.       if (col>7){gotoligcol(lig,col);
  272.       temp=tab[i][j];
  273.       tab[i][j]=tab[i][j-1];
  274.       tab[i][j-1]=temp;
  275.       gotoligcol(0,0);
  276.       affichage(tab);}else{gotoligcol(0,0);affichage(tab);}
  277.       soundAfterMove();
  278.       break;
  279.     case 'd':
  280.       if(col<85){gotoligcol(lig,col);
  281.       temp=tab[i][j];
  282.       tab[i][j]=tab[i][j+1];
  283.       tab[i][j+1]=temp;
  284.       gotoligcol(0,0);
  285.       affichage(tab);}else{gotoligcol(0,0);affichage(tab);}
  286.       soundAfterMove();
  287.       break;
  288.     case 'w':
  289.       if (lig>3){gotoligcol(lig,col);
  290.       temp=tab[i][j];
  291.       tab[i][j]=tab[i-1][j];
  292.       tab[i-1][j]=temp;
  293.       gotoligcol(0,0);
  294.       affichage(tab);}else{gotoligcol(0,0);affichage(tab);}
  295.       soundAfterMove();
  296.       break;
  297.  
  298.     default :
  299.         gotoligcol(0,0);affichage(tab);
  300.         soundAfterMove();
  301.         break;
  302.  
  303.     }
  304.  
  305. }
  306.  
  307. void curseur(int lig, int col, char tab[20][40], t_level unNiveau, int lesPoints[5])
  308. {   //déplace uniquement le curseur en appelant gotoligco. Si le joueur appuit sur la touche "ESPACE", alors elle appelle echangercoo
  309.   int nbcoup=unNiveau.allowedMoves;
  310.     gotoligcol(50,4);color(8,0);printf("Appuyez sur 0 pour quitter");color(15,0);
  311.     gotoligcol(4, 90); color(12,0);printf("Coups restants : %d  ", nbcoup);color(15,0);
  312.     gotoligcol(7,90);color(3,0);printf("\t\t Score : ");color(15,0);
  313.     gotoligcol(9,90);if(lesPoints[0]>=unNiveau.goalS){color(0,2);}else{color(2,0);}printf("\t    Points S : %d / %d \t\t", lesPoints[0], unNiveau.goalS);gotoligcol(9,130);color(15,0);printf("\t\t");
  314.     gotoligcol(10,90);if(lesPoints[1]>=unNiveau.goalF){color(0,2);}else{color(2,0);}printf("\t    Points F : %d / %d \t\t", lesPoints[1], unNiveau.goalF);gotoligcol(10,130);color(15,0);printf("\t\t");
  315.     gotoligcol(11,90);if(lesPoints[2]>=unNiveau.goalP){color(0,2);}else{color(2,0);}printf("\t    Points P : %d / %d \t\t", lesPoints[2], unNiveau.goalP);gotoligcol(11,130);color(15,0);printf(" \t\t");
  316.     gotoligcol(12,90);if(lesPoints[3]>=unNiveau.goalO){color(0,2);}else{color(2,0);}printf("\t    Points O : %d / %d \t\t", lesPoints[3], unNiveau.goalO);gotoligcol(12,130);color(15,0);printf("\t\t");
  317.     gotoligcol(13,90);if(lesPoints[4]>=unNiveau.goalM){color(0,2);}else{color(2,0);}printf("\t    Points M : %d / %d \t\t", lesPoints[4], unNiveau.goalM);gotoligcol(13,130);color(15,0);printf("\t\t");
  318.   char choix=getch();
  319.   int i, j;
  320.   i=0; j=0;
  321.   do
  322.     {
  323.       choix=getch();
  324.       switch(choix)
  325.     {
  326.     case 's':
  327.       if(lig<40){lig+=2; i++;}
  328.       gotoligcol(lig,col);
  329.         soundMove();
  330.         break;
  331.     case 'a':
  332.       if(col>7){col-=2; j--;}
  333.       gotoligcol(lig,col);
  334.       soundMove();
  335.       break;
  336.     case 'd':
  337.       if(col<85){col+=2; j++;}
  338.       gotoligcol(lig,col);
  339.       soundMove();
  340.       break;
  341.     case 'w':
  342.       if(lig>3){lig-=2; i--;}
  343.       gotoligcol(lig,col);
  344.       soundMove();
  345.       break;
  346.  
  347.     case 'p':
  348.         gotoligcol(0,0);printf("Case %d %d : %c \t", i, j, tab[i][j]);
  349.         break;
  350.  
  351.     case ' ':
  352.       gotoligcol(lig,col);
  353.       soundSelect();
  354.       nbcoup--;
  355.       tab[i][j]+=32;
  356.         if(tab[i][j]=='s'){color(13, 0);}
  357.         if(tab[i][j]=='f'){color(12, 0);}
  358.         if(tab[i][j]=='p'){color(10, 0);}
  359.         if(tab[i][j]=='o'){color(9, 0);}
  360.         if(tab[i][j]=='m'){color(3, 0);}
  361.       printf("%c",tab[i][j]);
  362.       gotoligcol(4, 90); if(nbcoup<6){color(0,12);}else{color(12,0);};printf("Coups restants : %d  ", nbcoup);
  363.       color(15, 0);
  364.       echangercoo(lig, col, i,j, tab);
  365.       while(nothingToSuppr(tab)==0){verification(tab,unNiveau,lesPoints);gotoligcol(0,0); affichage(tab);DingSound();Sleep(100);if(ligneDeCinq(tab)==1){refill(tab);}else{refill2(tab);}gotoligcol(0,0);affichage(tab);Sleep(100);
  366.                                     if(lesPoints[0]>1000 && lesPoints[1]>1000 && lesPoints[2]>1000 && lesPoints[3]>1000 && lesPoints[4]>1000){break;}}
  367.  
  368.       break;
  369.  
  370.     case '0' :
  371.         system("cls");
  372.         color(15,0);
  373.         printf("\n\n\n\n\n\n\n\t\t\t\t Au-revoir! \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  374.         exit(0);
  375.         break;
  376.  
  377.     default :
  378.         gotoligcol(lig,col);
  379.         break;
  380.     }
  381.     }
  382.   while (nbcoup>0 && !won(unNiveau, lesPoints));
  383.   if(nbcoup==0){//animation GAME OVER
  384.     waitFor(3);system("cls");
  385.   printf("\n\n\t\t\tVous n'avez plus de coups!");
  386.   color(12,0);
  387.     printf("\n\n\n"
  388.                                                 "\n\t  ________                        ________                     \n"
  389.                                                 "\t /  _____/_____    _____   ____   \\_____  \\___  __ ___________ \n"
  390.                                                 "\t/   \\  ___\\__  \\  /     \\_/ __ \\   /   |   \\  \\/ // __ \\_  __ \\ \n"
  391.                                                 "\t\\    \\_\\  \\/ __ \\|  Y Y  \\  ___/  /    |    \\   /\\  ___/|  | \\/ \n"
  392.                                                 "\t \\______  (____  /__|_|  /\\___  > \\_______  /\\_/  \\___  >__|   \n"
  393.                                                 "\t        \\/     \\/      \\/     \\/          \\/          \\/       ");
  394.     color(15,0);
  395.     GameOverSound();
  396.     getch();
  397.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n");
  398.   }
  399.   if(won(unNiveau, lesPoints)){//animation GAME WON
  400.         int i;
  401.         WonSound();
  402.         for(i=0; i<30;i++){
  403.         system("cls");
  404.         int laCouleur = (i%9)+1;
  405.         Sleep(50);
  406.         color(laCouleur,0);
  407.         gotoligcol(15,30);printf("Y88b   d88P  .d88888b.  888     888      888       888  .d88888b.  888b    888      \n");
  408.         gotoligcol(16,30);printf(" Y88b d88P  d88P' 'Y88b 888     888      888   o   888 d88P' 'Y88b 8888b   888      \n");
  409.         gotoligcol(17,30);printf("  Y88o88P   888     888 888     888      888  d8b  888 888     888 88888b  888      \n");
  410.         gotoligcol(18,30);printf("   Y888P    888     888 888     888      888 d888b 888 888     888 888Y88b 888      \n");
  411.         gotoligcol(19,30);printf("    888     888     888 888     888      888d88888b888 888     888 888 Y88b888      \n");
  412.         gotoligcol(20,30);printf("    888     888     888 888     888      88888P Y88888 888     888 888  Y88888      \n");
  413.         gotoligcol(21,30);printf("    888     Y88b. .d88P Y88b. .d88P      8888P   Y8888 Y88b. .d88P 888   Y8888      \n");
  414.         gotoligcol(22,30);printf("    888      'Y88888P'   'Y88888P'       888P     Y888  'Y88888P'  888    Y888      \n");
  415.         Sleep(50);
  416.         }
  417.         color(12,0);gotoligcol(28,37); printf("Voulez vous enregistrer votre magnifique victoire? Y: oui N : non\n\n\n");color(15,0);
  418.   }
  419. }
  420.  
  421. int won(t_level unNiveau, int lesPoints[5]){//fonction qui teste si le niveau est gagné
  422.     if(lesPoints[0]>=unNiveau.goalS && lesPoints[1]>=unNiveau.goalF && lesPoints[2]>=unNiveau.goalP && lesPoints[3]>=unNiveau.goalO &&lesPoints[4]>=unNiveau.goalM){return 1;}
  423.     else {return 0;}
  424. }
  425.  
  426. void waitFor (unsigned int secs) {     //fonction qui pause
  427.     unsigned int retTime;
  428.     retTime = time(0) + secs;     // Get finishing time.
  429.     while (time(0) < retTime);    // Loop until it arrives.
  430. }
  431.  
  432. void deleteCase(char tab[20][40], int i, int j){ //supprime une case en la remplacant par un '.'
  433.     tab[i][j]='.';
  434. }
  435.  
  436. void supprimer(char tab[20][40]){      //si cette fonction détecte 3 lettres de suite en ligne ou colonne, elle les supprime. Cette fonction est utilisée lors de la création du tableau uniquement
  437.     int i, j;
  438.     for(i=0; i<20; i++){
  439.         for(j=0; j<40; j++){
  440.             if((tab[i][j]==tab[i-1][j] && tab[i][j]==tab[i-2][j])){deleteCase(tab, i, j);deleteCase(tab, i-1, j);deleteCase(tab, i-2, j);}
  441.             if(tab[i][j]==tab[i][j-1] && tab[i][j]==tab[i][j-2]){deleteCase(tab, i, j); deleteCase(tab, i, j-1); deleteCase(tab, i, j-2);}
  442.     }
  443. }
  444. }
  445.  
  446. void fillCase(char tab[20][40], int i, int j){  //remplit une case
  447. //ici on prend une case particuliere et on utilise rand() pour lui donner aléatoirement une valeur
  448. //la fonction rand() a pris comme paramètre le temps dans la fonction fillTab pour que les suites de valeurs soient "réellement" aléatoires
  449.     int variable = rand()%5;
  450.     if(variable==0){tab[i][j]='S';}
  451.     if(variable==1){tab[i][j]='F';}
  452.     if(variable==2){tab[i][j]='P';}
  453.     if(variable==3){tab[i][j]='O';}
  454.     if(variable==4){tab[i][j]='M';}
  455. }
  456.  
  457. void affichage(char tab[20][40]){ //affiche le tableau
  458.     //affichage basique d'un tableau
  459.     int i, j;
  460.     printf("\n\n");
  461.     for(i=0; i<20; i++ ){
  462.             printf("\n       ");
  463.         for(j=0; j<40; j++){
  464.             if((tab[i][j]>='a') && (tab[i][j]<='z')){tab[i][j]-=32;}
  465.             if(tab[i][j]=='S'){color(13, 0);}
  466.             if(tab[i][j]=='F'){color(12, 0);}
  467.             if(tab[i][j]=='P'){color(10, 0);}
  468.             if(tab[i][j]=='O'){color(9, 0);}
  469.             if(tab[i][j]=='M'){color(3, 0);}
  470.             printf("%c ", tab[i][j]);
  471.             color(15,0);
  472.         }
  473.         printf("\n");
  474.     }
  475. }
  476.  
  477. void fillTab(char tab[20][40]){ //parcourt le tableau et rempli les cases une par une, en appelant fillCase
  478.  
  479.  
  480.     int i, j;
  481.     for(i=0; i<20; i++){
  482.         for(j=0; j<40; j++){
  483.             fillCase(tab, i, j);
  484.         }
  485.     }
  486. }
  487.  
  488. int thereIsEmpty(char tab[20][40]){ //si une case est supprimée, vérifie que celles d'au dessus sont supprimée aussi
  489.         int i, j, k;
  490.         int alors = 0;
  491.         for(i=0; i<20; i++){
  492.             for(j=0;j<40;j++){
  493.                 if(tab[i][j]=='.'){
  494.                     for(k=i-1; k>=0; k--){
  495.                         if(tab[k][j]!='.'){alors = 1;}
  496.                     }
  497.  
  498.                 }
  499.             }
  500.         }
  501.     return alors;
  502. }
  503.  
  504. void refill2(char tab[20][40]){ //refill2 est la même fonction que refill mais elle note un temps de pause avant de faire descendre les lettres
  505.     int i, j;
  506.     char temp;
  507.     while(thereIsEmpty(tab)){
  508.     for(i=1; i<20; i++){
  509.         for(j=0; j<40; j++){
  510.             if(tab[i][j]=='.'){
  511.                 temp=tab[i][j];
  512.                 tab[i][j]=tab[i-1][j];
  513.                 tab[i-1][j]=temp;
  514.                 Sleep(1);
  515.                 gotoligcol(0,0);affichage(tab);
  516.             }
  517.         }
  518.     }
  519. }
  520.     for(i=0; i< 20; i++){
  521.         for(j=0;j<40; j++){
  522.             if(tab[i][j]!='S' && tab[i][j]!='F' && tab[i][j]!='P' && tab[i][j]!='O' && tab[i][j]!='M'){fillCase(tab, i, j);}
  523.         }
  524.     }
  525.  
  526. }
  527.  
  528. void refill(char tab[20][40]){  //elle remplit instantanément, sans marquer de pause. Utilisée pour la création du tableau et pour le cas des 5 lettres de suite
  529.     int i, j;
  530.     char temp;
  531.     while(thereIsEmpty(tab)){
  532.     for(i=1; i<20; i++){
  533.         for(j=0; j<40; j++){
  534.             if(tab[i][j]=='.'){
  535.                 temp=tab[i][j];
  536.                 tab[i][j]=tab[i-1][j];
  537.                 tab[i-1][j]=temp;
  538.             }
  539.         }
  540.     }
  541. }
  542.     for(i=0; i< 20; i++){
  543.         for(j=0;j<40; j++){
  544.             if(tab[i][j]!='S' && tab[i][j]!='F' && tab[i][j]!='P' && tab[i][j]!='O' && tab[i][j]!='M'){fillCase(tab, i, j);}
  545.         }
  546.     }
  547. }
  548.  
  549. int isClean(char tab[20][40]){  //renvoie 0 si y'a quelque chose à supprimer.
  550.  
  551.     /*noter que les deux fonctions isClean et clean ne cherchent que des combinaisons à 3 lettres puisqu'elles ne servent qu'a préparer la matrice "en fond"
  552.     avant de commencer à jouer */
  553.     int isIt = 0;
  554.     int i, j;
  555.     for(i=0; i<20; i++){
  556.         for(j=0; j<40; j++){
  557.             if((tab[i][j]==tab[i-1][j] && tab[i][j]==tab[i-2][j])){isIt=1;}
  558.             if(tab[i][j]==tab[i][j-1] && tab[i][j]==tab[i][j-2]){isIt=1;}
  559.     }
  560. }
  561.  
  562.     return isIt;
  563. }
  564.  
  565. void clean(char tab[20][40]){  //"nettoie" le tableau tant qu'il y a quelque chose à supprimer
  566.     while(isClean(tab)){
  567.         supprimer(tab);
  568.         refill(tab);
  569.     }
  570. }
  571.  
  572. void play(t_level unNiveau){  //
  573.     int lesPoints[5] = {0,0,0,0,0}; //on va se servir de ce tableau pour compter les points
  574.     affichage(unNiveau.tableau);
  575.     curseur(3, 7, unNiveau.tableau, unNiveau, lesPoints); //on place le curseur sur la ligne 3, colonne 7 (premiere case du tableau)
  576. }
  577.  
  578. void menu(t_level niveau1, t_level niveau2){
  579.     char choix;
  580.     color(11,0);
  581.     gotoligcol(5,30); printf("888b     d888 8888888888 888b    888 888     888 ");
  582.     gotoligcol(6,30); printf("8888b   d8888 888        8888b   888 888     888 ");
  583.     gotoligcol(7,30); printf("88888b.d88888 888        88888b  888 888     888 ");
  584.     gotoligcol(8,30); printf("888Y88888P888 8888888    888Y88b 888 888     888 ");
  585.     gotoligcol(9,30); printf("888 Y888P 888 888        888 Y88b888 888     888 ");
  586.     gotoligcol(10,30);printf("888  Y8P  888 888        888  Y88888 888     888 ");
  587.     gotoligcol(11,30);printf("888   ^   888 888        888   Y8888 Y88b. .d88P ");
  588.     gotoligcol(12,30);printf("888       888 8888888888 888    Y888  ^Y88888P^  ");
  589.     color(15,0);
  590.     gotoligcol(15,20);color(2,0);printf("******* 1. Niveau 1 : 10 fraises, 20 oignons et 10 mandarines en 40 coups");
  591.     gotoligcol(17,20);printf("******* 2. Niveau 2 : 25 soleils, 15 pommes, 10 fraises et 15 oignons en 50 coups");
  592.     gotoligcol(19,20);printf("******* 3. Voir les meilleurs scores");
  593.     gotoligcol(21,20);printf("******* 4. Afficher les regles");
  594.     gotoligcol(23,20);color(8,0); printf("******* 0. Quitter");
  595.     printf("\n\n \t");
  596.     choix = getch();
  597.     color(15,0);
  598.  
  599.     switch(choix){
  600.  
  601.         case '1' :
  602.             system("cls");
  603.             play(niveau1);
  604.             break;
  605.  
  606.         case '2' :
  607.             system("cls");
  608.             play(niveau2);
  609.             break;
  610.  
  611.         case '3' :
  612.             printf("\n option pas encore accessible");
  613.             break;
  614.  
  615.         case '4' :
  616.             system("cls");
  617.             color(12, 0);
  618.             printf("\n\n \t Regles du jeu :");
  619.             color(15,0);
  620.             printf("\n\n \t\t 2 : Aller vers le bas \n \t\t 4 : Aller vers la gauche \n \t\t 6 : Aller vers la droite \n \t\t 8 : Aller vers le haut");
  621.             printf("\n\n \t\t La touche espace selectionne un element du tableau et vous pouvez alors le deplacer en utilisant les touches 2, 4, 6 et 8.");
  622.             printf("\n\n \t\t Dans chaque niveau vous devez atteindre un certain nombre de points fruits en un nombre limité de coups.");
  623.             printf("\n\n \t\t Vous obtenez des points en creant des combinaisons d'au moins 3 memes fruits, des croix ou des L. \n \t\t Faire une suite de 5 fruits supprime tous les fruits du meme type sur le terrain.");
  624.             color(12,0);printf("\n\n \t\t\t Points FRAISE    : F");
  625.             color(13,0);printf("\n\n \t\t\t Points SOLEIL    : S");
  626.             color(10,0);printf("\n\n \t\t\t Points POMME     : P");
  627.             color(9,0);printf("\n\n \t\t\t Points OIGON     : O");
  628.             color(3,0);printf("\n\n \t\t\t Points MANDARINE : M");
  629.             color(4,0);
  630.             printf("\n\n");
  631.             printf("\n \t\t Appuyez sur une touche pour revenir au menu.");
  632.             color(15,0);
  633.             getch();
  634.             system("cls");
  635.             menu(niveau1, niveau2);
  636.             break;
  637.  
  638.         case '0' :
  639.             printf("\n\n \t\tAu-revoir! \n\n");
  640.             break;
  641.  
  642.         default : color(12,0);printf("\n\t\tCommande invalide.");
  643.             menu(niveau1, niveau2);
  644.             break;
  645.     }
  646. }
  647.  
  648. int main()
  649. {
  650.     srand((unsigned)time(NULL));
  651.     t_level niveau1, niveau2;
  652.  
  653.     {//mise en place des niveaux
  654.     fillTab(niveau1.tableau);clean(niveau1.tableau);niveau1.allowedMoves=40;niveau1.goalS=0;niveau1.goalF=10;niveau1.goalP=0;niveau1.goalO=20;niveau1.goalM=10;niveau1.pointF=0;niveau1.pointM=0;niveau1.pointO=0;niveau1.pointP=0;niveau1.pointS=0; //mise en place du niveau1
  655.     fillTab(niveau2.tableau);clean(niveau2.tableau);niveau2.allowedMoves=50;niveau2.goalS=25;niveau2.goalF=10;niveau2.goalP=15;niveau2.goalO=15;niveau2.goalM=0;niveau2.pointF=0;niveau2.pointM=0;niveau2.pointO=0;niveau2.pointP=0;niveau2.pointS=0;} //mise en place du niveau2
  656.  
  657.     printf("\n\n \t\t\t\t Bienvenue sur \n\n");
  658.     color(11, 0);
  659.     printf("\n\n\t\t8888888b.  888             d8888 888b    888 88888888888     d8888 888b     d888 8888888 8888888888P "
  660.            "\n\n\t\t888   Y88b 888            d88888 8888b   888     888        d88888 8888b   d8888   888         d88P  "
  661.            "\n\n\t\t888    888 888           d88P888 88888b  888     888       d88P888 88888b.d88888   888        d88P   "
  662.            "\n\n\t\t888   d88P 888          d88P 888 888Y88b 888     888      d88P 888 888Y88888P888   888       d88P    "
  663.            "\n\n\t\t8888888PP  888         d88P  888 888 Y88b888     888     d88P  888 888 Y888P 888   888      d88P     "
  664.            "\n\n\t\t888        888        d88P   888 888  Y88888     888    d88P   888 888  Y8P  888   888     d88P      "
  665.            "\n\n\t\t888        888       d8888888888 888   Y8888     888   d8888888888 888       888   888    d88P       "
  666.            "\n\n\t\t888        88888888 d88P     888 888    Y888     888  d88P     888 888       888 8888888 d8888888888 \n\n");
  667.     color(2,0); printf("\n\n\t\t\t\t\t Un jeu ecrit par Axel Cante, Mohammed Mahfoud et Emilien Boucaud.");
  668.     color(12, 0);
  669.     printf("\n\n\t\t\t\t Appuyez sur une touche pour jouer"); color(15,0);
  670.     WelcomeSound();
  671.     getch();
  672.     system("cls");
  673.     menu(niveau1, niveau2);
  674.     return 0;
  675. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement