salut a tous,
je suis débutant dans le langage C
et je suis entrain de construire le jeux de tank si vous le savez
mais ce pendant le programme se plante aprés quelque secondes
le programme est a propos d'un deplacement aleatoire et rectiligne d'un char
si vous voulez bien m'aidez et merci bien
voici mon bout de code

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
#define hauteur 640
#define largeur 480
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#endif
 
int Random (int Min, int Max)
{
return (Min + (rand () % (Max-Min+1)));
}
 
 
 
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *tank = NULL;
SDL_Rect positiontank;
 
int choix,continuer=1;
 
    SDL_Init(SDL_INIT_VIDEO);
 
    ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE); /* Double Buffering */
    SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
 
    tank = SDL_LoadBMP("tank.bmp");
 
    SDL_SetColorKey(tank, SDL_SRCCOLORKEY, SDL_MapRGB(tank->format, 0, 0, 255));
 
    positiontank.x = ecran->w / 2 - tank->w / 2;
    positiontank.y = ecran->h / 2 - tank->h / 2;
 
 
 
 
while (continuer)
 
{
srand(time(NULL));
choix=Random(1,4);
 
 
 switch(choix)
 {
 
 
        case 1://HAUT
            positiontank.y--;
            Sleep(3);
            break;
 
 
        case 2://BAS
               if((positiontank.y + tank->h)<(ecran->h))
               {
               positiontank.y++;
               Sleep(3);
 
               }
        break;
 
 
        case 3://DROITE
                if((positiontank.x + tank->w)<(ecran->w))
                    {positiontank.x++;
                      Sleep(3);
                    }
        break;
 
        case 4://GAUCHE
            positiontank.x--;
            Sleep(3);
            break;
 
     }
 
 
 
 
     SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255,255, 255));
     SDL_BlitSurface(tank, NULL, ecran, &positiontank);
     SDL_Flip(ecran);
 
}
 
   SDL_FreeSurface(tank);
 
 
return EXIT_SUCCESS;
}