tron

le jeu des motos dans tron - retour accueil

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

Log | Files | Refs | README |

commit 03b7f8ae1f2586fdafee5c16a037cca31253d48a
parent a6bdb42f551f3407c28d614486baeb2af20e270e
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Thu, 26 Jun 2025 14:44:45 +0200

Ajouter et suppr des voitures dans l'écran titre

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

diff --git a/tron.c b/tron.c @@ -2,9 +2,9 @@ #include "termbox2.h" #include <time.h> -#define TAIL 50 -#define MAX_CAR_NUMBER 4 -#define NB_PLAYERS 1 +#define TAIL 100 +#define MAX_CAR_NUMBER 3 +#define NB_PLAYERS 2 enum direction { UP, RIGHT, DOWN, LEFT }; enum status { DEAD, ALIVE }; @@ -102,6 +102,23 @@ void createcar(int color, struct cars *cars, struct arena a) { cars->count++; } +void display_title_screen(int height, int width) { + tb_printf(width/2-35/2,height/2-5/2,0,0,"\ +████████ ██████  ██████  ███  ██\n\ +   ██    ██   ██ ██    ██ ████  ██\n\ + ██  ██████  ██  ██ ██ ██  ██\n\ + ██  ██   ██ ██  ██ ██  ██ ██\n\ + ██  ██  ██  ██████  ██   ████"); + + tb_printf(width/2-35/2,height/2-5/2+5+2,0,0,"\ +Entrée pour continuer\n\ ++ pour ajouter une voiture\n\ +- pour retirer une voiture\n\ +Voiture 1 ←↑→↓\n\ +Voiture 2 zqsd\n\ +Voiture 3 ijkl\n"); +} + int main(int argc, char **argv) { int ticknb=0; @@ -127,27 +144,36 @@ int main(int argc, char **argv) { struct cars cars; cars.count=0; cars.list=malloc(MAX_CAR_NUMBER*sizeof(struct car)); for(int i=0;i<NB_PLAYERS;i++) - createcar(2+cars.count, &cars, arena); + createcar(2+cars.count%8, &cars, arena); int timeout=80; + /*TITRE*/ + for(int i=0;i<cars.count;i++) if(cars.list[i].status==ALIVE) update(&cars.list[i],incs,ticknb); - display(cars,ticknb,TAIL,arena,timeout); - tb_printf(width/2-35/2,height/2-5/2,0,0,"████████ ██████  ██████  ███  ██\n\ -   ██    ██   ██ ██    ██ ████  ██\n\ - ██  ██████  ██  ██ ██ ██  ██\n\ - ██  ██   ██ ██  ██ ██  ██ ██\n\ - ██  ██  ██  ██████  ██   ████"); - - tb_printf(width/2-35/2,height/2-5/2+5+2,0,0,"Entrée pour continuer\nVoiture 1 ←↑→↓\nVoiture 2 zqsd "); - tb_present(); while(ev.key!=13) { + tb_clear(); + display_title_screen(height, width); + display(cars,ticknb,TAIL,arena,timeout); + tb_present(); tb_poll_event(&ev); + switch(ev.ch) { + case 43: /*+*/ + if (cars.count>=MAX_CAR_NUMBER) break; + createcar(cars.count%8+2,&cars,arena); + update(&cars.list[cars.count-1],incs,ticknb); + break; + case 45: /*-*/ + kill_car(&cars,cars.count-1); + break; + } } + /*On joue*/ + while(1) { for(int i=0;i<cars.count;i++) update(&cars.list[i],incs,ticknb);