apexsquirt

Pendu (v2)

Oct 17th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. bool in_array (char needle, char haystack[36]) {
  5.     int i;
  6.     for (i = 0; i < 36; i++) {
  7.         if (needle == haystack[i]) return true;
  8.     }
  9.     return false;
  10. }
  11.  
  12. bool egalite (char a1[36], char a2[36]) {
  13.     int i;
  14.     for (i = 0; i < 36; i++) {
  15.         if (a1[i] != a2[i]) return false;
  16.     }
  17.     return true;
  18. }
  19.  
  20. void changer (char needle, char hidstack[36], char haystack[36]) {
  21.     int i;
  22.     for (i = 0; i < 36; i++) {
  23.         if (needle == haystack[i]) hidstack[i] = haystack[i];
  24.     }
  25. }
  26.  
  27. int main () {
  28.    
  29.     int cursX, cursY, i, x, y, get, essais;
  30.     char mot[36], dec[36], pendu[9][6],
  31.     oui[2][3] = {{'O','U','I'},{'O','u','i'}},
  32.     non[2][3] = {{'N','o','n'},{'N','O','N'}};
  33.     bool stillgoing, perdu;
  34.    
  35.     init:
  36.         cursX = 0;
  37.         essais = 0;
  38.         for (x = 0; x < 9; x++) {
  39.             for (y = 0; y < 6; y++) {
  40.                 pendu[x][y] = ' ';
  41.             }
  42.         }
  43.         stillgoing = true;
  44.         perdu = false;
  45.         cursX = 0;
  46.         for (i = 0; i < 36; i++) {
  47.             mot[i] = '_';
  48.             dec[i] = '_';
  49.         }
  50.         while (1 < 2) {
  51.             system("cls");
  52.             printf("            Saisir un mot\n[");
  53.             for (i = 0; i < 36; i++) {
  54.                 printf("%c",mot[i]);
  55.             }
  56.             printf("]\n");
  57.             get = getch();
  58.             if (get >= 'a' and get <= 'z') {
  59.                 mot[cursX] = get;
  60.                 if (cursX+1 < 36) cursX++;
  61.             }
  62.             if (get == 8 and cursX > 0) {
  63.                 cursX--;
  64.                 mot[cursX] = '_';
  65.             }
  66.             if (get == 13) {
  67.                 goto pendu;
  68.             }
  69.         }
  70.    
  71.     pendu:
  72.         system("cls");
  73.         while (stillgoing) {
  74.             for (y = 0; y < 6; y++) {
  75.                 for (x = 0; x < 9+36+2; x++) {
  76.                     if (x < 9 and y < 6) {
  77.                         printf("%c",pendu[x][y]);
  78.                     }
  79.                     if (x == 9 and y == 3) printf("     ");
  80.                     if (x > 10 and y == 3 and mot[x-11] != '_') {
  81.                         printf("%c",dec[x-11]);
  82.                     }
  83.                 }
  84.                 printf("%c",'\n');
  85.             }
  86.             if (perdu) goto perdu;
  87.             get = getch();
  88.             if (in_array(get,mot)) {
  89.                 changer(get,dec,mot);
  90.                 system("cls");
  91.             } else {
  92.                 essais++;
  93.                 system("cls");
  94.             }
  95.             if (egalite(dec,mot)) goto gagner;
  96.             if (essais == 1) {
  97.                 for (i = 0; i < 3; i++) pendu[i][5] = '\xC4';
  98.             }
  99.             if (essais == 2) {
  100.                 pendu[1][5] = '\xC1';
  101.                 for (i = 1; i < 5; i++) pendu[1][i] = '\xB3';
  102.             }
  103.             if (essais == 3) {
  104.                 for (i = 0; i < 9; i++) pendu[i][0] = '_';
  105.             }
  106.             if (essais == 4) pendu[2][1] = '/';
  107.             if (essais == 5) pendu[7][1] = '|';
  108.             if (essais == 6) pendu[7][2] = 'O';
  109.             if (essais == 7) pendu[7][3] = '|';
  110.             if (essais == 8) pendu[6][3] = '/';
  111.             if (essais == 9) pendu[8][3] = '\x5C';
  112.             if (essais == 10) pendu[6][4] = '/';
  113.             if (essais == 11) {
  114.                 pendu[8][4] = '\x5C';
  115.                 perdu = true;
  116.                 goto perdu;
  117.             }
  118.             system("cls");
  119.         }
  120.    
  121.     gagner:
  122.         for (y = 0; y < 6; y++) {
  123.             for (x = 0; x < 9+36+2; x++) {
  124.                 if (x < 9 and y < 6) {
  125.                     printf("%c",pendu[x][y]);
  126.                 }
  127.                 if (x == 9 and y == 3) printf("     ");
  128.                 if (x > 10 and y == 3 and mot[x-11] != '_') {
  129.                     printf("%c",dec[x-11]);
  130.                 }
  131.             }
  132.             printf("%c",'\n');
  133.         }
  134.         printf("Gagn%c !",'\x82');
  135.         system("pause>nul");
  136.         cursX = 0;
  137.         goto reinit;
  138.    
  139.     perdu:
  140.         for (y = 0; y < 6; y++) {
  141.             for (x = 0; x < 9+36+2; x++) {
  142.                 if (x < 9 and y < 6) {
  143.                     printf("%c",pendu[x][y]);
  144.                 }
  145.                 if (x == 9 and y == 3) printf("     ");
  146.                 if (x > 10 and y == 3 and mot[x-11] != '_') {
  147.                     printf("%c",dec[x-11]);
  148.                 }
  149.             }
  150.             printf("%c",'\n');
  151.         }
  152.         printf("mdrr grosse merde");
  153.         system("pause>nul");
  154.         cursX = 0;
  155.         goto reinit;
  156.        
  157.     reinit:
  158.         system("cls");
  159.         printf("Continuer ?\n");
  160.         for (i = 0; i < 3; i++) {
  161.             printf("%c",oui[cursX][i]);
  162.         }
  163.         printf(" ");
  164.         for (i = 0; i < 3; i++) {
  165.             printf("%c",non[cursX][i]);
  166.         }
  167.         printf("\n");
  168.         get = getch();
  169.         if (get == 75 and cursX == 1) cursX = 0;
  170.         if (get == 77 and cursX == 0) cursX = 1;
  171.         if (get == 13) {
  172.             if (cursX == 0) goto init;
  173.             else return 0;
  174.         }
  175.         goto reinit;
  176.    
  177. }
Advertisement
Add Comment
Please, Sign In to add comment