tron

le jeu des motos dans tron - retour accueil

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

Log | Files | Refs | README |

commit 0d26e040904b1e14ce8a5bb72c8eed215e1358a5
parent bd985f60a1468e73acf0cba6d30d72b314644e5e
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Thu, 19 Jun 2025 18:50:04 +0200

Les voitures se colisionnent entre elles et couleur

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

diff --git a/tron.c b/tron.c @@ -14,17 +14,18 @@ struct car { coord position; coord* path; int direction; + int color; }; void display(struct car *cars, int ticks, int tail) { for (int i=0;i<2;i++) { - tb_printf(cars[i].position.x,cars[i].position.y,0,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,0,0,"▒"); + 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,0,0,"▒"); - tb_printf(0,i,0,0,"car %d - x: %d, y: %d, direction %d",i,cars[i].position.x,cars[i].position.y,cars[i].direction); + 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); } } @@ -35,13 +36,12 @@ void update(struct car *car, coord *incs, int ticks) { } int is_in_conflict(struct car *cars, int ticks, int tail) { - for (int i=0;i<2;i++) { - for (int j=ticks-tail;j<ticks+1;j++) { - if (cars[i].position.x==cars[i].path[j].x && - cars[i].position.y==cars[i].path[j].y) - return i+1; - } - } + for (int i=0;i<2;i++) + for (int j=ticks-tail;j<ticks+1;j++) + for (int k=0;k<2;k++) + if (cars[i].position.x==cars[k].path[j].x && + cars[i].position.y==cars[k].path[j].y) + return i+1; return 0; } @@ -57,8 +57,10 @@ int main(int argc, char **argv) { struct car c1; c1.position.x=10; c1.position.y=10; c1.path=malloc(sizeof(coord)*300); c1.direction=DOWN; + c1.color=TB_MAGENTA; struct car c2; c2.position.x=5; c2.position.y=5; c2.path=malloc(sizeof(coord)*300); c2.direction=UP; + c2.color=TB_CYAN; struct car cars[2]; cars[0]=c1; cars[1]=c2;