tron

le jeu des motos dans tron - retour accueil

git clone git://bebou.netlib.re/tron

Log | Files | Refs | README |

commit e8f3297b7a83b3457abc82bec6424d299c7b46f8
parent be810432b88a9f321c7e635e6b42773816f6f97d
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 25 Jun 2025 15:42:55 +0200

Facto init des voitures

On init le tableau de la queue n'importe comment, faut tout changer

Diffstat:
Mtron.c | 23+++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/tron.c b/tron.c @@ -72,6 +72,15 @@ int rd(int min, int max) { return (rand()%(max-min+1))+min; } +struct car createcar(int color, struct arena a) { + struct car c; + c.path=malloc(sizeof(coord)*900); + c.color=color; + c.position.x=rd(10,a.width-10); c.position.y=rd(10,a.height-10); + if(c.position.x<a.width/2) c.direction=RIGHT; else c.direction=LEFT; + return c; +} + int main(int argc, char **argv) { int ticknb=0; @@ -94,18 +103,8 @@ int main(int argc, char **argv) { struct arena arena; arena.width=width-1; arena.height=height-4; - struct car c1; - c1.path=malloc(sizeof(coord)*900); - c1.color=TB_MAGENTA; - struct car c2; - c2.path=malloc(sizeof(coord)*900); - c2.color=TB_CYAN; - - c1.position.x=rd(10,width-10); c1.position.y=rd(10,height-10); - c2.position.x=rd(10,width-10); c2.position.y=rd(10,height-10); - - if(c1.position.x<width/2) c1.direction=RIGHT; else c1.direction=LEFT; - if(c2.position.x<width/2) c2.direction=RIGHT; else c2.direction=LEFT; + struct car c1 = createcar(TB_MAGENTA, arena); + struct car c2 = createcar(TB_CYAN, arena); struct car cars[2]; cars[0]=c1; cars[1]=c2;