Bonjour a tous !
Je dois programmer le jeu snake, et nous serons noté sur ce projet.
Mais il s'avère que je suis bloqué dès les premières étapes....
Donc je vous remercie d'avance pour votre aide qui me sera bien précieuse !
Voila ce que j'ai fais déjà :
Le "o" (le 2) étant la nourriture s'affiche mais lorsque je relance le programme le "o" est au même endroit... Comment ce fais-ce ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdlib.h> #include <stdio.h> #include <time.h> #include <stdbool.h> int Alea() { return (rand()%(23 - 0 + 1) +1); } int main() { int tableau[24][24], i, j; for(i=0;i<24;i++) { for(j=0;j<24;j++) { if (((i == 0) || (j == 0)) || (i == 23) || (j == 23)) { tableau[i][j] = 1; } else(tableau[i][j] = 0); { printf(" "); } } } int nourriture; nourriture = 0; while (nourriture < 1) { i = Alea(); j = Alea(); while (tableau[i][j] == 1) { i = Alea(); j = Alea(); } tableau[i][j] = 2; nourriture++; } for(i=0;i<24;i++) { for(j=0;j<24;j++) { if (tableau[i][j] == 0) { printf(" "); } if (tableau[i][j] == 1) { printf(" #"); } if (tableau[i][j] == 2) { printf(" o"); } } printf(" \n"); } return 0; }
Partager