le jeu des motos dans tron - retour accueil
git clone git://bebou.netlib.re/tron
Log | Files | Refs | README |
commit 27f4a3ff2eacd6372224c66da917e6173f0a2108 parent a5b539e2d868ae8cdd377505942b7818213b4d1b Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 19 Jun 2025 21:55:19 +0200 On accélère avec le temps Aussi y'a un souci avec la queue, j'ai donné plus de mémoire mais en réalité c'est bête. Faut avoir un tableau de la longueur de la taille et le gérer comme ça mais là de suite flemme. Diffstat:
M | tron.c | | | 18 | +++++++++++------- |
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tron.c b/tron.c @@ -23,7 +23,7 @@ struct arena { int height; }; -void display(struct car *cars, int ticks, int tail, struct arena arena) { +void display(struct car *cars, int ticks, int tail, struct arena arena, int timeout) { for (int i=0;i<2;i++) { tb_printf(cars[i].position.x,cars[i].position.y,cars[i].color,0,"●"); for (int j=ticks-tail;j<ticks+1;j++) @@ -31,8 +31,9 @@ void display(struct car *cars, int ticks, int tail, struct arena arena) { tb_printf(cars[i].path[j].x,cars[i].path[j].y,cars[i].color,0,"▒"); else tb_printf(cars[i].path[j].x,cars[i].path[j].y,cars[i].color,0,"▒"); - tb_printf(0,tb_height()-i-1,cars[i].color,0,"car %d - x: %d, y: %d, direction %d",i,cars[i].position.x,cars[i].position.y,cars[i].direction); + tb_printf(0,arena.height+i+1,cars[i].color,0,"car %d - x: %d, y: %d, direction %d",i,cars[i].position.x,cars[i].position.y,cars[i].direction); } + tb_printf(0,arena.height+3,0,0,"tick %d, speed %d",ticks,timeout); tb_print(0,0,0,0,"╭"); tb_print(0,arena.height,0,0,"╰"); tb_print(arena.width,0,0,0,"╮"); @@ -91,13 +92,13 @@ int main(int argc, char **argv) { int height=tb_height(); int width=tb_width(); struct arena arena; - arena.width=width-1; arena.height=height-3; + arena.width=width-1; arena.height=height-4; struct car c1; - c1.path=malloc(sizeof(coord)*300); + c1.path=malloc(sizeof(coord)*900); c1.color=TB_MAGENTA; struct car c2; - c2.path=malloc(sizeof(coord)*300); + c2.path=malloc(sizeof(coord)*900); c2.color=TB_CYAN; c1.position.x=rd(10,width-10); c1.position.y=rd(10,height-10); @@ -109,6 +110,8 @@ int main(int argc, char **argv) { struct car cars[2]; cars[0]=c1; cars[1]=c2; + int timeout=80; + while(1) { for(int i=0;i<2;i++) update(&cars[i],incs,ticknb); @@ -119,9 +122,10 @@ int main(int argc, char **argv) { return 0; } tb_clear(); - display(cars,ticknb,TAIL,arena); + display(cars,ticknb,TAIL,arena,timeout); tb_present(); - tb_peek_event(&ev, 100); + tb_peek_event(&ev, timeout); + if(ticknb%10==0 && timeout>30) timeout--; switch(ev.ch) { case 122: /*z*/ if(cars[1].direction!=DOWN) cars[1].direction=UP;