1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
void aff_game(int *line)
{
int i;
int j;
int nbsp;
i = 0;
nbsp = (line[4] / 2 + line[4] % 2) - 1;
while (i < 5)
{
j = 0;
while (j++ < nbsp)
my_putchar(' ');
nbsp -= 1;
j = 0;
while (j++ < line[i])
my_putchar('|');
my_putchar('\n');
i++;
}
}
int remain_line(int *line)
{
int i;
int nb;
nb = 0;
i = 0;
while (i < 5)
{
nb += line[i];
i++;
}
return (nb);
}
void check(int nb_match, int *line, int c)
{
int x;
if (nb_match > 0 && line[c - 1] >= nb_match)
{
x = remain_line(line) - 1;
if (x > nb_match)
{
line[c - 1] = line[c - 1] - nb_match;
system("clear");
aff_game(line);
printf("%i\n", x);
}
if (remain_line(line) == 1)
printf("PERDU\n");
}
else
{
printf("\n\033[0;32m> ERREUR vous avez supprimer plus d'allumettes qu'il en reste ou vous avez ren\
tre un chiffre non valide\n veuillez recommander svp\033[0m\n");
}
}
void alum()
{
int *line;
int nb_match;
char *c;
char *d;
line = malloc(10 * sizeof(int));
c = malloc(4 * sizeof(char));
d = malloc(25 * sizeof(char));
line[0] = 1;
line[1] = 3;
line[2] = 5;
line[3] = 7;
line[4] = 9;
aff_game(line);
while (1)
{
my_putstr("Quelle collone selectionnez vous ?\n");
read(STDIN_FILENO, c, READ_BUFF);
my_putstr("Combiens d allumettes selectionnez vous ?\n");
read(STDIN_FILENO, d, READ_BUFF);
nb_match = atoi(d);
check(nb_match, line, atoi(c));
}
} |
Partager