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 9fd601206b6baaaef888fa9684f72516fada0762 parent c9fe61299a1680f1d9a661e9a0c80e08f8d69a73 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 22 Jan 2025 20:05:53 +0100 J'essaye les trucs ternaires là Je relis du code et ça me fait un peu peur la logique de mouvement des selections et cartes Diffstat:
M | interface.c | | | 29 | ++++++++--------------------- |
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/interface.c b/interface.c @@ -25,7 +25,7 @@ int max(int a, int b) { return a > b ? a : b; } int nblines(char *str) { int l=0; for (int i = 0; str[i] != '\0'; i++) - if (str[i]=='\n') { l++; } + if (str[i]=='\n') l++; return l; } @@ -53,10 +53,8 @@ bool addcardtopile(char* cardname, pile* p, pile **piles) { /*On quitte si l'argument est vide ou s'il contient un espace*/ /* strchr ne fonctionne pas avec utf-8 mais pour le moment rien * ne fonctionne en utf8 alors bon */ - if(cardname[0]=='\0' || strchr(cardname,' ')!=NULL) - return false; - if(p->name=="played") - addcardtopile("none",piles[PLAYEDARGS],piles); + if(cardname[0]=='\0' || strchr(cardname,' ')!=NULL) return false; + if(p->name=="played") addcardtopile("none",piles[PLAYEDARGS],piles); if(p->name=="playedargs" && strcmp(cardname,"none")!=0) p->cards[p->cardCount-1]=cardname; else { @@ -85,11 +83,7 @@ void removecardofpile(int cardposition, pile* p, pile **piles) { } pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { - int step; - if (direction == "up") - step = -1; - else - step = 1; + int step = direction == "up" ? -1 : 1 ; if (p->curline+step >= 0 && p->curline+step < p->cardCount) { if (selection) { char* tmp; @@ -108,8 +102,7 @@ pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { } void updatecmd(char* cmd, pile **p) { - if (p[PLAYED]->cardCount == 0 ) - return; + if (p[PLAYED]->cardCount == 0 ) return; strcat(cmd,"( cat ./"); strcat(cmd,p[PLAYED]->cards[0]); if(strcmp(p[PLAYEDARGS]->cards[0],"none")!=0) { @@ -159,16 +152,10 @@ void file2pile(char* filename, pile *p, pile **piles) { int displaypile(pile p, pile curmenu, int rowoffset, int lineoffset, bool selection) { int newlineoffset=lineoffset; for (int i=0;i<p.cardCount;i++) { - char* name; - if (strcmp(p.cards[i],"none")==0) - name=" "; - else - name=p.cards[i]; + char *name = strcmp(p.cards[i],"none")==0 ? " " : p.cards[i] ; if (i==p.curline && p.name == curmenu.name ) { - if (selection) - tb_printf(rowoffset, lineoffset+i, TB_BLACK, TB_BLUE, name); - else - tb_printf(rowoffset, lineoffset+i, TB_BLACK, TB_WHITE, name); + int background = selection ? TB_BLUE : TB_WHITE ; + tb_printf(rowoffset, lineoffset+i, TB_BLACK, background, name); } else tb_printf(rowoffset, lineoffset+i, TB_DEFAULT, TB_DEFAULT, name);