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 16bc69d9f5ebe8ad97599f435fc45d9b6c44e348 parent e6ff1df44c0562ab2ac2fd38124c716505ddf2c5 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 22 Jan 2025 16:52:23 +0100 Les {} sont facultatifs sur une ligne Diffstat:
M | interface.c | | | 62 | ++++++++++++++++++++++++++++++++++++-------------------------- |
1 file changed, 36 insertions(+), 26 deletions(-)
diff --git a/interface.c b/interface.c @@ -24,21 +24,22 @@ 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++; } } + for (int i = 0; str[i] != '\0'; i++) + if (str[i]=='\n') { l++; } return l; } void hr(int rowoffset, int lineoffset, int length) { char ruler[length+1]; - for(int i=0;i<length;i++){ruler[i]='-';} + for(int i=0;i<length;i++) + ruler[i]='-'; ruler[length]='\0'; tb_printf(rowoffset, lineoffset, TB_DEFAULT, TB_DEFAULT, ruler); } void vr(int rowoffset, int lineoffset, int length) { - for (int i=0;i<length;i++) { + for (int i=0;i<length;i++) tb_printf(rowoffset,lineoffset+i,TB_DEFAULT, TB_DEFAULT, "|"); - } } pile createpile(char *name) { @@ -53,12 +54,11 @@ bool addcardtopile(char* cardname, pile* p, pile **piles) { /* 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") { + if(p->name=="played") addcardtopile("none",piles[PLAYEDARGS],piles); - } - if(p->name=="playedargs" && cardname!="none") { + if(p->name=="playedargs" && cardname!="none") strcpy(p->cards[p->cardCount-1], cardname); - } else { + else { p->cards[p->cardCount] = malloc(CARD_NAME_SIZE); strcpy(p->cards[p->cardCount], cardname); p->cardCount++; @@ -69,9 +69,8 @@ bool addcardtopile(char* cardname, pile* p, pile **piles) { void removecardofpile(int cardposition, pile* p, pile **piles) { if(p->name=="played") { - if(strcmp(piles[PLAYEDARGS]->cards[cardposition],"none")!=0) { + if(strcmp(piles[PLAYEDARGS]->cards[cardposition],"none")!=0) addcardtopile(piles[PLAYEDARGS]->cards[cardposition],piles[ARGS],piles); - } removecardofpile(cardposition,piles[PLAYEDARGS],piles); } else if(p->name=="playedargs" && strcmp(p->cards[cardposition],"none")!=0) { p->cards[cardposition]="none"; @@ -79,14 +78,17 @@ void removecardofpile(int cardposition, pile* p, pile **piles) { } p->cardCount--; for(int i=cardposition;i<p->cardCount;i++) - { p->cards[i]=p->cards[i+1]; } - if (p->curline>0) { p->curline--; } + p->cards[i]=p->cards[i+1]; + if (p->curline>0) + p->curline--; } pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { int step; - if (direction == "up") { step = -1; } - else { step = 1; } + if (direction == "up") + step = -1; + else + step = 1; if (p->curline+step >= 0 && p->curline+step < p->cardCount) { if (selection) { char* tmp; @@ -97,13 +99,16 @@ pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { p->curline=p->curline+step; return p; } - if (p->name=="hand" && direction == "down" && piles[ARGS]->cardCount>0) { return piles[ARGS]; } - else if (p->name=="args" && direction == "up" && piles[HAND]->cardCount>0) { return piles[HAND]; } + if (p->name=="hand" && direction == "down" && piles[ARGS]->cardCount>0) + return piles[ARGS]; + else if (p->name=="args" && direction == "up" && piles[HAND]->cardCount>0) + return piles[HAND]; return p; } 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]); for (int i=1;i<p[PLAYED]->cardCount;i++) { @@ -114,22 +119,21 @@ void updatecmd(char* cmd, pile **p) { } void updateinterncmd(char *res, const pile p) { - if (p.cardCount == 0 ) { return; } + if (p.cardCount == 0 ) + return; for(int i=0;i<p.cardCount;i++) { FILE *fp = fopen(p.cards[i], "r"); char line[CMD_LINE_SIZE];line[0]='\0'; - while(fgets(line, sizeof(line), fp)) { + while(fgets(line, sizeof(line), fp)) strcat(res, line); - } } } void updateres(char *res, const char *cmd, FILE *fp) { fp = popen(cmd,"r"); char line[CMD_LINE_SIZE]; - while(fgets(line, sizeof(line), fp)) { + while(fgets(line, sizeof(line), fp)) strcat(res, line); - } } void file2pile(char* filename, pile *p, pile **piles) { @@ -147,12 +151,18 @@ int displaypile(pile p, pile curmenu, int rowoffset, int lineoffset, bool select 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]; } + if (strcmp(p.cards[i],"none")==0) + name=" "; + else + name=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); } + if (selection) + tb_printf(rowoffset, lineoffset+i, TB_BLACK, TB_BLUE, name); + else + tb_printf(rowoffset, lineoffset+i, TB_BLACK, TB_WHITE, name); } - else { tb_printf(rowoffset, lineoffset+i, TB_DEFAULT, TB_DEFAULT, name); } + else + tb_printf(rowoffset, lineoffset+i, TB_DEFAULT, TB_DEFAULT, name); newlineoffset++; } hr(rowoffset,newlineoffset,7);