je fais un jeu style serpent mais je ne connais pas encore les pointeur alors j'ai fais ça mais ça tourne pas pouvez vous m'expliqué un peu merci bien :
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>
typedef struct{
int x;
int y;
}point;
point p2[50];
void afficheballedeb()
{
p2[0].x =320;
p2[0].y =240;
setfillstyle(SOLID_FILL, RED);
bar(p2[0].x,p2[0].y,p2[0].x+4,p2[0].y+4);
p2[1].x =324;
p2[1].y =240;
setfillstyle(SOLID_FILL, RED);
bar(p2[1].x,p2[1].y,p2[1].x+4,p2[1].y+4);
p2[2].x =328;
p2[2].y =240;
setfillstyle(SOLID_FILL, RED);
bar(p2[2].x,p2[2].y,p2[2].x+4,p2[2].y+4);
}
void changeTable(int indmax,int indtete,int dx, int dy)
{
if ( indtete<indmax )
{
p2[indtete].x=p2[indtete].x+dx;
p2[indtete].y=p2[indtete].y+dy;
}
else
{
indtete=0;
}
}
void afficheballered(int indtete)
{
setfillstyle(SOLID_FILL, RED);
bar(p2[indtete].x,p2[indtete].y,p2[indtete].x+3,p2[indtete].y+3);
}
void afficheterrain()
{
rectangle(0,0,639,479);
}
void graphicdriver()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
}
//-------------------------------------------------------------------//
// //
// //
// D.E.B.U.T SERPENT //
// //
// //
//-------------------------------------------------------------------//
int main(void)
{
int i,x,y,dx,dy,indtete,indmax;
char car;
graphicdriver();
afficheballedeb();
indtete=0;
indmax=2;
while ( car!=27 )
{
if (kbhit())
{
car = getch();
if (car==72)
{
dx = -1;
dy = 0;
}
if (car==80)
{
dx = 0;
dy = -1;
}
if (car==75)
{
dx = 0;
dy = 1;
}
if (car==77)
{
dx = 1;
dy = 0;
}
}
changeTable(indmax,indtete,dx,dy);
indtete=indtete+1;
afficheballered(indtete);
afficheterrain();
delay(20);
}
/* clean up */
closegraph();
return 0;
}