Bah, relis ma réponse complètement...Envoyé par Electroniktor
Bah, relis ma réponse complètement...Envoyé par Electroniktor
J'ai essayé de faire passer la fonction move_plot() en paramètre de la fonction move_ball() mais je n'y arrive pas. J'avais mis ...
... mais je ne peux pas mettre deux fois *this.
Code : Sélectionner tout - Visualiser dans une fenêtre à part static void move_ball (struct ball *this, struct plot *this)![]()
Alors j'aimerais savoir si à la place de this, je peux mettre n'importe quel mot, ou si il y a des mots bien spéciaux ?!![]()
bien sûr que tu peux mettre n'importe quoi....Envoyé par Electroniktor
Emmanuel met this pour se rapprocher de ce qui se fait en langage objet.. mais ça ne va pas plus loin..
Tu veux sans doute dire la structure ?Envoyé par Electroniktor
Je mettrais p_ball et p_plot... tu fais comme tu veux, du moment que c'est clair. Evite les horreurs genre a, b ou pa, pb ou p1, p2...de la fonction move_ball() mais je n'y arrive pas. J'avais mis ...
... mais je ne peux pas mettre deux fois *this.
Code : Sélectionner tout - Visualiser dans une fenêtre à part static void move_ball (struct ball *this, struct plot *this)![]()
Alors j'aimerais savoir si à la place de this, je peux mettre n'importe quel mot, ou si il y a des mots bien spéciaux ?!
Bon ben j'ai fait le code, mais le jeu a parfois un comportement bizare
: parfois, la balle est renvoyée lorsque il n'y a pas de raquette
! Et je ne vois d'où cela vient ...
![]()
Le voilà:
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio2.h> #include "affichage.h" #define MS(ms) (CLOCKS_PER_SEC / (1000.0 / (ms))) #define X_MIN 17 #define X_MAX 65 #define Y_MIN 6 #define Y_MAX 22 enum dir { NW, NE, SE, SW }; struct ball { int x; int y; enum dir dir; }; struct plot { int x; int y ; }; int end = 0; static void move_ball (struct ball *this, struct plot *that, int *end) { if (this->x == 41) { gotoxy (this->x, this->y), putch ('|'); } else { gotoxy (this->x, this->y), putch (' '); } switch (this->dir) { case NW: this->x--; this->y--; if (this->x == that->y && this->y == Y_MIN) { this->dir = SE; this->x++; this->y++; } else if (this->x == that->y) { this->dir = NE; this->x++; } else if (this->y == Y_MIN) { this->dir = SW; this->y++; } else if (this->x == X_MIN) { *end = 1; } break; case NE: this->x++; this->y--; if (this->x == X_MAX && this->y == Y_MIN) { this->dir = SW; this->x--; this->y++; } else if (this->x == X_MAX) { this->dir = NW; this->x--; } else if (this->y == Y_MIN) { this->dir = SE; this->y++; } break; case SE: this->x++; this->y++; if (this->x == X_MAX && this->y == Y_MAX) { this->dir = NW; this->x--; this->y--; } else if (this->x == X_MAX) { this->dir = SW; this->x--; } else if (this->y == Y_MAX) { this->dir = NE; this->y--; } break; case SW: this->x--; this->y++; if (this->x == that->y && this->y == Y_MAX) { this->dir = NE; this->x++; this->y--; } else if (this->x == that->y) { this->dir = SE; this->x++; } else if (this->y == Y_MAX) { this->dir = NW; this->y--; } else if(this->x == X_MIN) { *end = 1; } break; } gotoxy (this->x, this->y), putch ('o'); } static void move_plot (struct plot *this, int c) { switch (c) { case '2': if (this->y < Y_MAX - 1) { gotoxy (this->x, this->y), putch (' '); this->y++; gotoxy (this->x, this->y), putch ('|'); } break; case '8': if (this->y > Y_MIN + 1) { gotoxy (this->x, this->y), putch (' '); this->y--; gotoxy (this->x, this->y), putch ('|'); } break; } } int main (void) { struct ball ball = { 40, 15, NW }; struct plot plot = { 19, 15 }; clock_t echeance = clock () + MS (100); titre(); terrain(); /* positions initiales */ gotoxy (ball.x, ball.y), putch ('o'); gotoxy (plot.x, plot.y), putch ('|'); /* mouvement */ do { if (clock () > echeance) { move_ball (&ball, &plot, &end); echeance = clock () + MS (100); } if (kbhit ()) { int c = getch (); switch (c) { case '2': case '8': move_plot (&plot, c); break; case 27: end = 1; } } } while (!end); getch(); return 0; }
Bah, il y a de l'idée, mais il faut plus réfléchir à l'algorithme, bien poser les conditions, bien commenter etc.Envoyé par Electroniktor
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio2.h> #include <windows.h> #if 0 #include "affichage.h" #endif #define MS(ms) (CLOCKS_PER_SEC / (1000.0 / (ms))) #define DELAY 250 #define X_MIN 17 #define X_MAX 65 #define Y_MIN 6 #define Y_MAX 22 enum dir { NW, NE, SE, SW }; struct ball { int x; int y; enum dir dir; }; struct plot { int x; int y; }; int end = 0; static void move_ball (struct ball *this, struct plot *p_plot, int *end) { /* Si il n'y a pas collision avec la raquette */ if (!(this->x == p_plot->x && this->y == p_plot->y)) { gotoxy (this->x, this->y), putch (' '); } switch (this->dir) { case NW: this->x--; this->y--; /* Si il y a collision avec la raquette */ if (this->x == p_plot->x && this->y == p_plot->y) { if (this->y == Y_MIN) { /* rebond a 180 degre */ this->dir = SE; this->x++; this->y++; } else { /* rebond a 90 degre */ this->dir = NE; this->x++; } } /* si touche le cote */ else if (this->y == Y_MIN) { /* rebond a 90 degre */ this->dir = SW; this->y++; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { *end = 1; } break; case NE: this->x++; this->y--; if (this->x == X_MAX && this->y == Y_MIN) { this->dir = SW; this->x--; this->y++; } else if (this->x == X_MAX) { this->dir = NW; this->x--; } else if (this->y == Y_MIN) { this->dir = SE; this->y++; } break; case SE: this->x++; this->y++; if (this->x == X_MAX && this->y == Y_MAX) { this->dir = NW; this->x--; this->y--; } else if (this->x == X_MAX) { this->dir = SW; this->x--; } else if (this->y == Y_MAX) { this->dir = NE; this->y--; } break; case SW: this->x--; this->y++; /* Si il y a collision avec la raquette */ if (this->x == p_plot->x && this->y == p_plot->y) { if (this->y == Y_MAX) { /* rebond a 180 degre */ this->dir = NE; this->x++; this->y--; } else { /* rebond a 90 degre */ this->dir = SE; this->x++; } } /* si touche le cote */ else if (this->y == Y_MAX) { /* rebond a 90 degre */ this->dir = NW; this->y--; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { *end = 1; } break; } gotoxy (this->x, this->y), putch ('o'); } static void move_plot (struct plot *this, int c) { switch (c) { case '2': if (this->y < Y_MAX - 1) { gotoxy (this->x, this->y), putch (' '); this->y++; gotoxy (this->x, this->y), putch ('|'); } break; case '8': if (this->y > Y_MIN + 1) { gotoxy (this->x, this->y), putch (' '); this->y--; gotoxy (this->x, this->y), putch ('|'); } break; } } int main (void) { struct ball ball = { 40, 15, NW }; struct plot plot = { 19, 15 }; clock_t echeance = clock () + MS (DELAY); #if 0 titre (); terrain (); #endif /* positions initiales */ gotoxy (ball.x, ball.y), putch ('o'); gotoxy (plot.x, plot.y), putch ('|'); /* mouvement */ do { if (clock () > echeance) { move_ball (&ball, &plot, &end); echeance = clock () + MS (DELAY); } if (kbhit ()) { int c = getch (); switch (c) { case '2': case '8': move_plot (&plot, c); break; case 27: end = 1; } } Sleep(1); } while (!end); return 0; }
C'est vrai que je ne suis pas très fort au niveau algorythmie, mais cela va venir ... enfin j'espère !![]()
En tout cas, j'ai modifié un peu ton code car cela n'affichait pas le titre et le terrain, et j'ai fait deux trois autres changements sans importance !![]()
Je vais maintenant essayé de faire une raquette composée de deux | qui renvoit la balle dans différentes directions suivant la partie de la raquette touchée. Je vais aussi faire un compteur de coup qui augmente la vitesse de la balle tous les 5 coups. Cela me fera ainsi le mode entraînement de mon jeu.![]()
Je m'attaquerai ensuite à un mode deux joueurs (je ne pense que cela sera très difficile !) et un mode un joueur contre l'ordinateur (là ce sera un peu plus dur à cause de l'algorythme à faire !) où on pourra enregistrer le meilleur score !![]()
Et merci beaucoup pour le code !![]()
Faut pas hésiter à faire des petits croquis, ça aide à réfléchir...Envoyé par Electroniktor
Oui j'ai fait un petit croquis du comportement que j'attend de la future raquette. Le voiçi. Je vais m'occuper de le coder demain.![]()
Bien sûr que c'est faisable, mais je préfèrerais qu'on utilise les pthreads qui sont plus portables, de même que je préfèrerais PDCurses à conio... Mais bon, le P.O. est parti comme ça, ce qui compte c'est l'algo. Le portage est un autre problème.Envoyé par frp31
Ne pas oublier non plus qu'il faut savoir détecter les collisions. Il faut donc pouvoir partager des données entre processus (balle, raquette...)... Compliqué. Là encore, les threads sont beaucoup plus simples.
Euh ... c'est quoi cette bibliothèque PDCurses ?![]()
Marche plus tonEnvoyé par Electroniktor
http://pdcurses.sourceforge.net/
Si mais je n'ai trouvé que des pages en anglais et d'après ce que j'ai compris, cela ne fonctionne que sur les sytèmes UNIX !![]()
Je voulais donc savoir si cela était vrai vu que je suis sou windows !![]()
Sinon, si je peux l'utiliser sous windows, je pourrais faire plein de trucs car les quelques fonctions présentées que j'ai trouvé m'ont l'air très utiles pour faire des jeux en console comme j'aime faire (bien que la plupart se retrouvent dans conio !)![]()
Bah, non, justement, PDCurses est portable, comme son nom l'indique... Mais on ne vas pas changer de bibliothèque maintenant. On verra plus tard comment le faire proprement.Envoyé par Electroniktor
Bon ben voilà j'ai codé la raquette à trois parties qui renvoie la balle dans diférente directions selon la partie touchée (voir dessin).![]()
Et en plus, ca marche !!!![]()
Le problème est que j'ai voulu faire un compteur de coups et qu'il ne marche pas !![]()
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio2.h> #include <windows.h> #include "affichage.h" #define MS(ms) (CLOCKS_PER_SEC / (1000.0 / (ms))) #define DELAY 250 #define X_MIN 17 #define X_MAX 65 #define Y_MIN 6 #define Y_MAX 22 enum dir { NW, NE, SE, SW }; struct ball { int x; int y; enum dir dir; }; struct plot { int x; int y1; int y2; int y3; }; int end = 0; long compteur = 0; static void move_ball (struct ball *this, struct plot *p_plot, int *end, long *compteur) { /* Si il n'y a pas collision avec la raquette */ if (!(this->x == p_plot->x && this->y == p_plot->y1 || this->x == p_plot->x && this->y == p_plot->y2 || this->x == p_plot->x && this->y == p_plot->y3)) { if (this->x == 41) { gotoxy (this->x, this->y), putch ('|'); } else if (this->x == X_MIN + 1) { gotoxy (this->x, this->y), putch ('o'); } else { gotoxy (this->x, this->y), putch (' '); } } switch (this->dir) { case NW: this->x--; this->y--; /* Si il y a collision avec la partie haute de la raquette */ if (this->x == p_plot->x && this->y == p_plot->y1) { /* rebond a 90 degre */ this->dir = NE; this->x++; *compteur++; } /* Si il y a collision avec la partie centrale de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y2) { this->dir = SE; this->x++; this->y++; *compteur++; } /* Si il y a collision avec la partie basse de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y3) { this->dir = SE; this->x++; this->y++; *compteur++; } /* si touche le cote */ else if (this->y == Y_MIN) { /* rebond a 90 degre */ this->dir = SW; this->y++; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { getch(); *end = 1; } break; case NE: this->x++; this->y--; if (this->x == X_MAX && this->y == Y_MIN) { this->dir = SW; this->x--; this->y++; } else if (this->x == X_MAX) { this->dir = NW; this->x--; } else if (this->y == Y_MIN) { this->dir = SE; this->y++; } break; case SE: this->x++; this->y++; if (this->x == X_MAX && this->y == Y_MAX) { this->dir = NW; this->x--; this->y--; } else if (this->x == X_MAX) { this->dir = SW; this->x--; } else if (this->y == Y_MAX) { this->dir = NE; this->y--; } break; case SW: this->x--; this->y++; /* Si il y a collision avec la partie haute de la raquette */ if (this->x == p_plot->x && this->y == p_plot->y1) { this->dir = NE; this->x++; this->y--; *compteur++; } /* Si il y a collision avec la partie centrale de la raquette */ else if(this->x == p_plot->x && this->y == p_plot->y2) { this->dir = NE; this->x++; this->y--; *compteur++; } /* Si il y a collision avec la partie basse de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y3) { this->dir = SE; this->x++; *compteur++; } /* si touche le cote */ else if (this->y == Y_MAX) { /* rebond a 90 degre */ this->dir = NW; this->y--; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { getch(); *end = 1; } break; } gotoxy (this->x, this->y), putch ('o'); } static void move_plot (struct plot *this, int c) { switch (c) { case '2': if (this->y3 < Y_MAX - 1) { this->y1++; gotoxy( this->x, this->y1), putch('|'); this->y2++; gotoxy( this->x, this->y2), putch('|'); this->y3++; gotoxy( this->x, this->y3), putch('|'); gotoxy( this->x, this->y1 - 1), putch(' '); } break; case '8': if (this->y1 > Y_MIN + 1) { this->y1--; gotoxy( this->x, this->y1), putch('|'); this->y2--; gotoxy( this->x, this->y2), putch('|'); this->y3--; gotoxy( this->x, this->y3), putch('|'); gotoxy( this->x, this->y3 + 1), putch(' '); } break; } } int main (void) { struct ball ball = { 40, 15, NW }; struct plot plot = { 19, 14, 15, 16 }; clock_t echeance = clock () + MS (DELAY); titre (); terrain (); /* positions initiales */ gotoxy (ball.x, ball.y), putch ('o'); gotoxy (plot.x, plot.y1), putch ('|'); gotoxy (plot.x, plot.y2), putch ('|'); gotoxy (plot.x, plot.y3), putch ('|'); /* mouvement */ do { if (clock () > echeance) { move_ball (&ball, &plot, &end, &compteur); echeance = clock () + MS (DELAY); } if (kbhit ()) { int c = getch (); switch (c) { case '2': case '8': move_plot (&plot, c); break; case 27: end = 1; } } gotoxy( 1, 1); printf("%ld", compteur); Sleep(1); } while (!end); return 0; }
Il vaudrait peut-être mieux que je fasse une fonction:
Code : Sélectionner tout - Visualiser dans une fenêtre à part void vitesse (struct plot *this, struct move_ball *that, *compteur, *DELAY)Cette fonction comptera le nombre de coups
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 */ en remplacant */ #define DELAY 250 */ par */ long DELAY = 250;en testant :
et en changeant la valeur de DELAY (= vitesse) tous les 5 coups selon l'échelle suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part this->y == that->x;
:
- 0 --> 250
- 5 --> 200
- 10 --> 150
- 15 --> 125
- 20 --> 100
- 25 --> 90
- 30 --> 80
- 35 --> 75
- 40 --> 70
- 45 --> 65
- 50 --> 60
- .....
Alors j'ai fait une fonction vitesse mais je ne suis pas allé plus loin car déjà le compteur de coups ne marche pas !![]()
Ensuite, pour règler la vitesse selon le nombre de coups, je pensais faire un switch sur compteur mais je me demandais, si je fais ...
... est ce que lorsque compteur est égal à 7, DELAY reste égal à 200 ? (j'ai la honte là !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 case 5 : DELAY = 200; break; case 10 : *DELAY = 150; break;)
Voiçi le début de ma fonction:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 static void vitesse (struct ball *this, struct plot *p_plot, long *compteur, long *DELAY) { if (this->x == p_plot->x && this->y == p_plot->y1 || this->x == p_plot->x && this->y == p_plot->y2 || this->x == p_plot->x && this->y == p_plot->y3) { *compteur++; gotoxy( 1, 1); printf("%ld", *compteur); } }
Ne fait pas ce que tu crois. :Envoyé par Electroniktor
C'est la valeur pointée que tu veux modifier et non le pointeur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part compteur++;
Code : Sélectionner tout - Visualiser dans une fenêtre à part (*compteur)++;
Voilà mon code. Le compteur marche mais un peu trop : le compteur augmente pendant toute la durée où la balle touche la raquette, ce qui donne à la fin de mon prmier coup un score de 122 ! Tu remarqueras que j'ai changé les valeurs des define car j'ai changé les dimensions du terrain !
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio2.h> #include <windows.h> #include "affichage.h" #define MS(ms) (CLOCKS_PER_SEC / (1000.0 / (ms))) #define X_MIN 11 #define X_MAX 71 #define Y_MIN 6 #define Y_MAX 22 enum dir { NW, NE, SE, SW }; struct ball { int x; int y; enum dir dir; }; struct plot { int x; int y1; int y2; int y3; }; int end = 0; long compteur = 0; long DELAY = 250; static void vitesse (struct ball *this, struct plot *p_plot, long *compteur, long *DELAY) { if (this->x == p_plot->x +1 && this->y == p_plot->y1 || this->x == p_plot->x +1 && this->y == p_plot->y2 || this->x == p_plot->x +1 && this->y == p_plot->y3) { (*compteur)++; gotoxy( 1, 1); printf("%ld", *compteur); } } static void move_ball (struct ball *this, struct plot *p_plot, int *end) { /* Si il n'y a pas collision avec la raquette */ if (!(this->x == p_plot->x && this->y == p_plot->y1 || this->x == p_plot->x && this->y == p_plot->y2 || this->x == p_plot->x && this->y == p_plot->y3)) { if (this->x == 41) { gotoxy (this->x, this->y), putch ('|'); } else if (this->x == X_MIN + 1) { gotoxy (this->x, this->y), putch ('o'); } else { gotoxy (this->x, this->y), putch (' '); } } switch (this->dir) { case NW: this->x--; this->y--; /* Si il y a collision avec la partie haute de la raquette */ if (this->x == p_plot->x && this->y == p_plot->y1) { /* rebond a 90 degre */ this->dir = NE; this->x++; } /* Si il y a collision avec la partie centrale de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y2) { this->dir = SE; this->x++; this->y++; } /* Si il y a collision avec la partie basse de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y3) { this->dir = SE; this->x++; this->y++; } /* si touche le cote */ else if (this->y == Y_MIN) { /* rebond a 90 degre */ this->dir = SW; this->y++; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { getch(); *end = 1; } break; case NE: this->x++; this->y--; if (this->x == X_MAX && this->y == Y_MIN) { this->dir = SW; this->x--; this->y++; } else if (this->x == X_MAX) { this->dir = NW; this->x--; } else if (this->y == Y_MIN) { this->dir = SE; this->y++; } break; case SE: this->x++; this->y++; if (this->x == X_MAX && this->y == Y_MAX) { this->dir = NW; this->x--; this->y--; } else if (this->x == X_MAX) { this->dir = SW; this->x--; } else if (this->y == Y_MAX) { this->dir = NE; this->y--; } break; case SW: this->x--; this->y++; /* Si il y a collision avec la partie haute de la raquette */ if (this->x == p_plot->x && this->y == p_plot->y1) { this->dir = NE; this->x++; this->y--; } /* Si il y a collision avec la partie centrale de la raquette */ else if(this->x == p_plot->x && this->y == p_plot->y2) { this->dir = NE; this->x++; this->y--; } /* Si il y a collision avec la partie basse de la raquette */ else if (this->x == p_plot->x && this->y == p_plot->y3) { this->dir = SE; this->x++; } /* si touche le cote */ else if (this->y == Y_MAX) { /* rebond a 90 degre */ this->dir = NW; this->y--; } /* si touche le fond ouest : perdu */ else if (this->x == X_MIN) { getch(); *end = 1; } break; } gotoxy (this->x, this->y), putch ('o'); } static void move_plot (struct plot *this, int c) { switch (c) { case '2': if (this->y3 < Y_MAX - 1) { this->y1++; gotoxy( this->x, this->y1), putch('|'); this->y2++; gotoxy( this->x, this->y2), putch('|'); this->y3++; gotoxy( this->x, this->y3), putch('|'); gotoxy( this->x, this->y1 - 1), putch(' '); } break; case '8': if (this->y1 > Y_MIN + 1) { this->y1--; gotoxy( this->x, this->y1), putch('|'); this->y2--; gotoxy( this->x, this->y2), putch('|'); this->y3--; gotoxy( this->x, this->y3), putch('|'); gotoxy( this->x, this->y3 + 1), putch(' '); } break; } } int main (void) { struct ball ball = { 40, 15, NW }; struct plot plot = { 13, 14, 15, 16 }; clock_t echeance = clock () + MS (DELAY); titre (); terrain (); /* positions initiales */ gotoxy (ball.x, ball.y), putch ('o'); gotoxy (plot.x, plot.y1), putch ('|'); gotoxy (plot.x, plot.y2), putch ('|'); gotoxy (plot.x, plot.y3), putch ('|'); /* mouvement */ do { if (clock () > echeance) { move_ball (&ball, &plot, &end); echeance = clock () + MS (DELAY); } if (kbhit ()) { int c = getch (); switch (c) { case '2': case '8': move_plot (&plot, c); break; case 27: end = 1; } } vitesse (&ball, &plot, &compteur, &DELAY); Sleep(1); } while (!end); return 0; }
Il y a probablement une erreur avec cette expression. Si tu n'es pas certain de la priorité des opérateurs, mets des parenthèses. Je suppose que tu veux :Envoyé par Electroniktor
et tu remarqueras la différence de présentation, qui permet un contrôle visuel immédiat de la 'régularité' du code...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 if ((this->x == p_plot->x +1 && this->y == p_plot->y1) || (this->x == p_plot->x +1 && this->y == p_plot->y2) || (this->x == p_plot->x +1 && this->y == p_plot->y3))
D'ailleurs, on voit que 'this->x == p_plot->x +1' peut être mis en facteur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 if (this->x == p_plot->x +1 && (this->y == p_plot->y1 || this->y == p_plot->y2 || this->y == p_plot->y3))
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager