Advertisement
Guest User

Pendu

a guest
Oct 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.10 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.                 pendu[0][5] = '\xC4';
  98.                 pendu[1][5] = '\xC4';
  99.                 pendu[2][5] = '\xC4';
  100.             }
  101.             if (essais == 2) {
  102.                 pendu[1][5] = '\xC1';
  103.                 pendu[1][4] = '\xB3';
  104.                 pendu[1][3] = '\xB3';
  105.                 pendu[1][2] = '\xB3';
  106.                 pendu[1][1] = '\xB3';
  107.             }
  108.             if (essais == 3) {
  109.                 pendu[0][0] = '_';
  110.                 pendu[1][0] = '_';
  111.                 pendu[2][0] = '_';
  112.                 pendu[3][0] = '_';
  113.                 pendu[4][0] = '_';
  114.                 pendu[5][0] = '_';
  115.                 pendu[6][0] = '_';
  116.                 pendu[7][0] = '_';
  117.                 pendu[8][0] = '_';
  118.             }
  119.             if (essais == 4) {
  120.                 pendu[2][1] = '/';
  121.             }
  122.             if (essais == 5) {
  123.                 pendu[7][1] = '|';
  124.             }
  125.             if (essais == 6) {
  126.                 pendu[7][2] = 'O';
  127.             }
  128.             if (essais == 7) {
  129.                 pendu[7][3] = '|';
  130.             }
  131.             if (essais == 8) {
  132.                 pendu[6][3] = '/';
  133.             }
  134.             if (essais == 9) {
  135.                 pendu[8][3] = '\x5C';
  136.             }
  137.             if (essais == 10) {
  138.                 pendu[6][4] = '/';
  139.             }
  140.             if (essais == 11) {
  141.                 pendu[8][4] = '\x5C';
  142.                 perdu = true;
  143.                 goto perdu;
  144.             }
  145.             system("cls");
  146.         }
  147.    
  148.     gagner:
  149.         for (y = 0; y < 6; y++) {
  150.             for (x = 0; x < 9+36+2; x++) {
  151.                 if (x < 9 and y < 6) {
  152.                     printf("%c",pendu[x][y]);
  153.                 }
  154.                 if (x == 9 and y == 3) printf("     ");
  155.                 if (x > 10 and y == 3 and mot[x-11] != '_') {
  156.                     printf("%c",dec[x-11]);
  157.                 }
  158.             }
  159.             printf("%c",'\n');
  160.         }
  161.         printf("Gagn%c !",'\x82');
  162.         system("pause>nul");
  163.         cursX = 0;
  164.         goto reinit;
  165.    
  166.     perdu:
  167.         for (y = 0; y < 6; y++) {
  168.             for (x = 0; x < 9+36+2; x++) {
  169.                 if (x < 9 and y < 6) {
  170.                     printf("%c",pendu[x][y]);
  171.                 }
  172.                 if (x == 9 and y == 3) printf("     ");
  173.                 if (x > 10 and y == 3 and mot[x-11] != '_') {
  174.                     printf("%c",dec[x-11]);
  175.                 }
  176.             }
  177.             printf("%c",'\n');
  178.         }
  179.         printf("mdrr grosse merde");
  180.         system("pause>nul");
  181.         cursX = 0;
  182.         goto reinit;
  183.        
  184.     reinit:
  185.         system("cls");
  186.         printf("Continuer ?\n");
  187.         for (i = 0; i < 3; i++) {
  188.             printf("%c",oui[cursX][i]);
  189.         }
  190.         printf(" ");
  191.         for (i = 0; i < 3; i++) {
  192.             printf("%c",non[cursX][i]);
  193.         }
  194.         printf("\n");
  195.         get = getch();
  196.         if (get == 75 and cursX == 1) cursX = 0;
  197.         if (get == 77 and cursX == 0) cursX = 1;
  198.         if (get == 13) {
  199.             if (cursX == 0) goto init;
  200.             else return 0;
  201.         }
  202.         goto reinit;
  203.    
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement