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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
void aff_match(int nb_match)
{
int i;
i = 0;
while (i < nb_match)
{
my_putstr("|");
++i;
}
my_putstr("\n");
}
void aff_game(int *line)
{
aff_match(line[0]);
aff_match(line[1]);
aff_match(line[2]);
aff_match(line[3]);
aff_match(line[4]);
}
int remain_line(int *line)
{
int i;
static int n;
n = 4;
i = 0;
while (i <= 4)
{
if (line[i] == 0)
n = n - 1;
i = i + 1;
}
return (n);
}
int remain_line1(int *line)
{
int i;
static int n;
n = 1;
i = 0;
while (i < 1)
{
if (line[i] == 0)
n = n - 1;
i = i + 1;
}
return (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(0, c, READ_BUFF);
my_putstr("Combiens d allumettes selectionnez vous ?\n");
read(0, d, READ_BUFF);
nb_match = atoi(d);
if (nb_match > 0 && line[atoi(c) - 1] >= nb_match)
{
if (remain_line(line) > 1)
{
line[atoi(c) - 1] = line[atoi(c) - 1] - nb_match;
system("clear");
aff_game(line);
}
else
{
printf("ek\n");
if (remain_line1(line) > 0)
{
system("clear");
printf("ee\n");
line[atoi(c) - 1] = line[atoi(c) - 1] - nb_match;
aff_game(line);
}
else
{
system("clear");
printf("aa\n");
aff_game(line);
exit (0);
}
}
}
}
} |
Partager