le jeu des motos dans tron - retour accueil
git clone git://bebou.netlib.re/tron
Log | Files | Refs | README |
commit e985d1d03aefd5c29f76720ddcbbed3d3f4845a1 parent 0d26e040904b1e14ce8a5bb72c8eed215e1358a5 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 19 Jun 2025 19:05:23 +0200 On trace les bordures de l'arène Diffstat:
M | tron.c | | | 30 | ++++++++++++++++++++++++++---- |
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/tron.c b/tron.c @@ -17,16 +17,34 @@ struct car { int color; }; -void display(struct car *cars, int ticks, int tail) { +struct arena { + int width; + int height; +}; + +void display(struct car *cars, int ticks, int tail, struct arena arena) { for (int i=0;i<2;i++) { - tb_printf(cars[i].position.x,cars[i].position.y,cars[i].color,0,"$"); + tb_printf(cars[i].position.x,cars[i].position.y,cars[i].color,0,"●"); for (int j=ticks-tail;j<ticks+1;j++) if(cars[i].path[j].x!=cars[i].path[j-1].x) 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,i,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,tb_height()-i,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_print(0,0,0,0,"╭"); + tb_print(0,arena.height,0,0,"╰"); + tb_print(arena.width,0,0,0,"╮"); + tb_print(arena.width,arena.height,0,0,"╯"); + for (int i=1;i<arena.width;i++) { + tb_print(i,0,0,0,"─"); + tb_print(i,arena.height,0,0,"─"); + } + for (int i=1;i<arena.height;i++) { + tb_print(0,i,0,0,"│"); + tb_print(arena.width,i,0,0,"│"); } + } void update(struct car *car, coord *incs, int ticks) { @@ -70,6 +88,10 @@ int main(int argc, char **argv) { tb_init(); tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); + + struct arena arena; + arena.width=tb_width()-1; arena.height=tb_height()-2; + struct tb_event ev; while(1) { for(int i=0;i<2;i++) @@ -81,7 +103,7 @@ int main(int argc, char **argv) { return 0; } tb_clear(); - display(cars,ticknb,TAIL); + display(cars,ticknb,TAIL,arena); tb_present(); tb_peek_event(&ev, 50); switch(ev.ch) {