Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- bool in_array (char needle, char haystack[36]) {
- int i;
- for (i = 0; i < 36; i++) {
- if (needle == haystack[i]) return true;
- }
- return false;
- }
- bool egalite (char a1[36], char a2[36]) {
- int i;
- for (i = 0; i < 36; i++) {
- if (a1[i] != a2[i]) return false;
- }
- return true;
- }
- void changer (char needle, char hidstack[36], char haystack[36]) {
- int i;
- for (i = 0; i < 36; i++) {
- if (needle == haystack[i]) hidstack[i] = haystack[i];
- }
- }
- int main () {
- int cursX, cursY, i, x, y, get, essais;
- char mot[36], dec[36], pendu[9][6],
- oui[2][3] = {{'O','U','I'},{'O','u','i'}},
- non[2][3] = {{'N','o','n'},{'N','O','N'}};
- bool stillgoing, perdu;
- init:
- cursX = 0;
- essais = 0;
- for (x = 0; x < 9; x++) {
- for (y = 0; y < 6; y++) {
- pendu[x][y] = ' ';
- }
- }
- stillgoing = true;
- perdu = false;
- cursX = 0;
- for (i = 0; i < 36; i++) {
- mot[i] = '_';
- dec[i] = '_';
- }
- while (1 < 2) {
- system("cls");
- printf(" Saisir un mot\n[");
- for (i = 0; i < 36; i++) {
- printf("%c",mot[i]);
- }
- printf("]\n");
- get = getch();
- if (get >= 'a' and get <= 'z') {
- mot[cursX] = get;
- if (cursX+1 < 36) cursX++;
- }
- if (get == 8 and cursX > 0) {
- cursX--;
- mot[cursX] = '_';
- }
- if (get == 13) {
- goto pendu;
- }
- }
- pendu:
- system("cls");
- while (stillgoing) {
- for (y = 0; y < 6; y++) {
- for (x = 0; x < 9+36+2; x++) {
- if (x < 9 and y < 6) {
- printf("%c",pendu[x][y]);
- }
- if (x == 9 and y == 3) printf(" ");
- if (x > 10 and y == 3 and mot[x-11] != '_') {
- printf("%c",dec[x-11]);
- }
- }
- printf("%c",'\n');
- }
- if (perdu) goto perdu;
- get = getch();
- if (in_array(get,mot)) {
- changer(get,dec,mot);
- system("cls");
- } else {
- essais++;
- system("cls");
- }
- if (egalite(dec,mot)) goto gagner;
- if (essais == 1) {
- pendu[0][5] = '\xC4';
- pendu[1][5] = '\xC4';
- pendu[2][5] = '\xC4';
- }
- if (essais == 2) {
- pendu[1][5] = '\xC1';
- pendu[1][4] = '\xB3';
- pendu[1][3] = '\xB3';
- pendu[1][2] = '\xB3';
- pendu[1][1] = '\xB3';
- }
- if (essais == 3) {
- pendu[0][0] = '_';
- pendu[1][0] = '_';
- pendu[2][0] = '_';
- pendu[3][0] = '_';
- pendu[4][0] = '_';
- pendu[5][0] = '_';
- pendu[6][0] = '_';
- pendu[7][0] = '_';
- pendu[8][0] = '_';
- }
- if (essais == 4) {
- pendu[2][1] = '/';
- }
- if (essais == 5) {
- pendu[7][1] = '|';
- }
- if (essais == 6) {
- pendu[7][2] = 'O';
- }
- if (essais == 7) {
- pendu[7][3] = '|';
- }
- if (essais == 8) {
- pendu[6][3] = '/';
- }
- if (essais == 9) {
- pendu[8][3] = '\x5C';
- }
- if (essais == 10) {
- pendu[6][4] = '/';
- }
- if (essais == 11) {
- pendu[8][4] = '\x5C';
- perdu = true;
- goto perdu;
- }
- system("cls");
- }
- gagner:
- for (y = 0; y < 6; y++) {
- for (x = 0; x < 9+36+2; x++) {
- if (x < 9 and y < 6) {
- printf("%c",pendu[x][y]);
- }
- if (x == 9 and y == 3) printf(" ");
- if (x > 10 and y == 3 and mot[x-11] != '_') {
- printf("%c",dec[x-11]);
- }
- }
- printf("%c",'\n');
- }
- printf("Gagn%c !",'\x82');
- system("pause>nul");
- cursX = 0;
- goto reinit;
- perdu:
- for (y = 0; y < 6; y++) {
- for (x = 0; x < 9+36+2; x++) {
- if (x < 9 and y < 6) {
- printf("%c",pendu[x][y]);
- }
- if (x == 9 and y == 3) printf(" ");
- if (x > 10 and y == 3 and mot[x-11] != '_') {
- printf("%c",dec[x-11]);
- }
- }
- printf("%c",'\n');
- }
- printf("mdrr grosse merde");
- system("pause>nul");
- cursX = 0;
- goto reinit;
- reinit:
- system("cls");
- printf("Continuer ?\n");
- for (i = 0; i < 3; i++) {
- printf("%c",oui[cursX][i]);
- }
- printf(" ");
- for (i = 0; i < 3; i++) {
- printf("%c",non[cursX][i]);
- }
- printf("\n");
- get = getch();
- if (get == 75 and cursX == 1) cursX = 0;
- if (get == 77 and cursX == 0) cursX = 1;
- if (get == 13) {
- if (cursX == 0) goto init;
- else return 0;
- }
- goto reinit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement