pipe-game

Un jeu de cartes à piper les une dans les autres - retour accueil

git clone git://bebou.netlib.re/pipe-game
Log | Files | Refs | README |

commit 26604dafe79b5d3c9af53d2062c0d34be3f8e6cc
parent be5ed0a1f6e0eaead2e3074a43a8f9701a663cd1
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Thu, 30 Jan 2025 21:31:34 +0100

Les piles sont faites avec des cara unicode !

Et celle qui est la courante est entourée, c'est fancyyy

Diffstat:
Minterface.c | 48+++++++++++++++++++++++++-----------------------
1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/interface.c b/interface.c @@ -40,18 +40,17 @@ int nblines(char *str) { return l; } -int hr(int coloffset, int lineoffset, int length) { - char ruler[length+1]; +int hr(int coloffset, int lineoffset, int length, bool selected) { + int color=selected ? TB_DEFAULT : TB_WHITE; for(int i=0;i<length;i++) - ruler[i]='-'; - ruler[length]='\0'; - tb_printf(coloffset, lineoffset, TB_DEFAULT, TB_DEFAULT, ruler); + tb_printf(coloffset+i, lineoffset, color, TB_DEFAULT, "─"); return lineoffset+1; } -void vr(int coloffset, int lineoffset, int length) { +void vr(int coloffset, int lineoffset, int length, bool selected) { + int color=selected ? TB_DEFAULT : TB_WHITE; for (int i=0;i<length;i++) - tb_printf(coloffset,lineoffset+i,TB_DEFAULT, TB_DEFAULT, "|"); + tb_printf(coloffset,lineoffset+i, color, TB_DEFAULT, "│"); } struct pile createpile(char *name) { @@ -184,30 +183,31 @@ void file2pile(FILE* fp, struct pile *p, struct pile **piles) { p->curline=0; } -coord displaybox(int coloffset, int lineoffset, int width, int length) { +coord displaybox(int coloffset, int lineoffset, int width, int length, bool selected) { + int color=selected ? TB_DEFAULT : TB_WHITE; length<2 ? length=2 : length; - hr(coloffset+1,lineoffset,width-1); - hr(coloffset+1,lineoffset+length,width-1); - vr(coloffset,lineoffset+1,length-1); - vr(coloffset+width,lineoffset+1,length-1); - tb_print(coloffset,lineoffset,TB_DEFAULT,TB_DEFAULT,"+"); - tb_print(coloffset+width,lineoffset,TB_DEFAULT,TB_DEFAULT,"+"); - tb_print(coloffset,lineoffset+length,TB_DEFAULT,TB_DEFAULT,"+"); - tb_print(coloffset+width,lineoffset+length,TB_DEFAULT,TB_DEFAULT,"+"); + hr(coloffset+1,lineoffset,width-1,selected); + hr(coloffset+1,lineoffset+length,width-1,selected); + vr(coloffset,lineoffset+1,length-1,selected); + vr(coloffset+width,lineoffset+1,length-1,selected); + tb_print(coloffset,lineoffset,color,TB_DEFAULT,"╭"); + tb_print(coloffset+width,lineoffset,color,TB_DEFAULT,"╮"); + tb_print(coloffset,lineoffset+length,color,TB_DEFAULT,"╰"); + tb_print(coloffset+width,lineoffset+length,color,TB_DEFAULT,"╯"); coord p; p.x=coloffset+width; p.y=lineoffset+length; return p; } -coord displaypile(struct pile *p, struct pile curmenu, int coloffset, int lineoffset, bool selection) { +coord displaypile(struct pile *p, struct pile *curmenu, int coloffset, int lineoffset, bool selection) { int newlineoffset=lineoffset; int maxwidth=CARD_NAME_SIZE+2; int maxlen=p->cardcount+1; coord begin; begin.x=coloffset; begin.y=lineoffset; - coord end=displaybox(begin.x,begin.y,maxwidth,maxlen); + coord end=displaybox(begin.x,begin.y,maxwidth,maxlen,p==curmenu); p->begin=begin; p->end=end; coloffset++; lineoffset++; for (int i=0;i<p->cardcount;i++) { char *name = strcmp(p->cards[i],"none")==0 ? " " : p->cards[i] ; - if (i==p->curline && p->name == curmenu.name ) { + if (i==p->curline && p == curmenu ) { int background = selection ? TB_BLUE : TB_WHITE ; tb_printf(coloffset, lineoffset+i, TB_BLACK, background, name); } @@ -221,7 +221,7 @@ coord displaypile(struct pile *p, struct pile curmenu, int coloffset, int lineof coord displaytextblock(char *text, int coloffset, int lineoffset) { coord p; int nbl=nblines(text), w=30; p.y=nbl+lineoffset; p.x=w+coloffset; - displaybox(coloffset,lineoffset,w,nbl); + displaybox(coloffset,lineoffset,w,nbl,false); coloffset++; lineoffset++; tb_printf(coloffset, lineoffset, TB_DEFAULT, TB_DEFAULT, text); return p; @@ -234,12 +234,13 @@ int debug(int l, struct pile curmenu,struct tb_event ev) { char str2[100]; sprintf(str2,"%d",curmenu.curline); tb_printf(0,l++,TB_DEFAULT,TB_DEFAULT,str2); - tb_printf(0,l++,TB_DEFAULT,TB_DEFAULT,"touche %d, char %d, x %d, y %d\n",ev.key,ev.ch,ev.x,ev.y); + tb_printf(0,l++,0,0,"█"); + tb_printf(0,l++,TB_DEFAULT,TB_DEFAULT,"touche█ %d, char %d, x %d, y %d\n",ev.key,ev.ch,ev.x,ev.y); tb_printf(0,l++,TB_DEFAULT,TB_DEFAULT,"type %d, mod %d, a %d",ev.type,ev.mod,TB_MOD_MOTION); return l; } -int display(struct pile** piles, struct pile curmenu, bool selection, char* cmd, char* res, +int display(struct pile** piles, struct pile *curmenu, bool selection, char* cmd, char* res, char* intern, char* cmdennemy, char* resennemy, char* internennemy) { coord p; tb_clear(); @@ -272,6 +273,7 @@ int display(struct pile** piles, struct pile curmenu, bool selection, char* cmd, int main(int argc, char **argv) { tb_init(); + tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); struct tb_event ev; coord prevpos; @@ -318,7 +320,7 @@ int main(int argc, char **argv) { updateinterncmd(intern, played); updateinterncmd(internennemy, playedennemy); - int l=display(piles,*curmenu,selection,cmd,res,intern,cmdennemy,resennemy,internennemy); + int l=display(piles,curmenu,selection,cmd,res,intern,cmdennemy,resennemy,internennemy); debug(l,*curmenu,ev); tb_present(); tb_poll_event(&ev);