le jeu des motos dans tron - retour accueil
git clone git://bebou.netlib.re/tron
Log | Files | Refs | README |
commit 6438d4e7d66d94ad49fe6c775d0bd7dd232146c1 parent 30aff340aa11b09cc1a87484e54ee5ed0f37be86 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 19 Jun 2025 21:32:33 +0200 Placement initial des voitures aléatoire Diffstat:
M | tron.c | | | 24 | +++++++++++++++++------- |
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/tron.c b/tron.c @@ -1,5 +1,6 @@ #define TB_IMPL #include "termbox2.h" +#include <time.h> #define TAIL 20 @@ -66,6 +67,10 @@ int is_in_conflict(struct car *cars, int ticks, int tail, struct arena arena) { return 0; } +int rd(int min, int max) { + return (rand()%(max-min+1))+min; +} + int main(int argc, char **argv) { int ticknb=0; @@ -76,26 +81,31 @@ int main(int argc, char **argv) { coord left; left.x=-1; left.y=0; coord incs[4] = { up, right, down, left }; - struct car c1; c1.position.x=10; c1.position.y=10; + srand(time(NULL)); + struct car c1; c1.path=malloc(sizeof(coord)*300); c1.direction=DOWN; c1.color=TB_MAGENTA; - struct car c2; c2.position.x=5; c2.position.y=5; + struct car c2; c2.path=malloc(sizeof(coord)*300); c2.direction=UP; c2.color=TB_CYAN; - struct car cars[2]; - cars[0]=c1; cars[1]=c2; - int dead_car; tb_init(); tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); + struct tb_event ev; + int height=tb_height(); int width=tb_width(); struct arena arena; - arena.width=tb_width()-1; arena.height=tb_height()-3; + arena.width=width-1; arena.height=height-3; + + c1.position.x=rd(5,width-5); c1.position.y=rd(5,height-5); + c2.position.x=rd(5,width-5); c2.position.y=rd(5,height-5); + + struct car cars[2]; + cars[0]=c1; cars[1]=c2; - struct tb_event ev; while(1) { for(int i=0;i<2;i++) update(&cars[i],incs,ticknb);