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 e2c92f6abac667c5f6b6ff036f298e2c3e7982e3 parent c3d37243ef292592e2e8fecbaee1824c16f8bcb9 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Sat, 25 Jan 2025 14:37:28 +0100 + pile ennemy args et affichage des piles ennemy copier/coller, copier/coller, faut factoriser tout ça Ou pas ? Parce que dans la théorie ça devrait être tout Je sais pas trop Diffstat:
M | interface.c | | | 57 | ++++++++++++++++++++++++++++++++++++--------------------- |
1 file changed, 36 insertions(+), 21 deletions(-)
diff --git a/interface.c b/interface.c @@ -18,7 +18,7 @@ typedef struct int curline; } pile; -enum pileid { HAND, PLAYED, ARGS, PLAYEDARGS, PLAYEDENNEMY }; +enum pileid { HAND, PLAYED, ARGS, PLAYEDARGS, PLAYEDENNEMY, PLAYEDENNEMYARGS }; int max(int a, int b) { return a > b ? a : b; } @@ -55,7 +55,8 @@ bool addcardtopile(char* cardname, pile* p, pile **piles) { * ne fonctionne en utf8 alors bon */ if(cardname[0]=='\0' || strchr(cardname,' ')!=NULL) return false; if(strcmp(p->name,"played")==0) addcardtopile("none",piles[PLAYEDARGS],piles); - if(strcmp(p->name,"playedargs")==0 && strcmp(cardname,"none")!=0) + if(strcmp(p->name,"playedennemy")==0) addcardtopile("none",piles[PLAYEDENNEMYARGS],piles); + if( ( strcmp(p->name,"playedargs")==0 || strcmp(p->name,"playedennemyargs")==0 ) && strcmp(cardname,"none")!=0) p->cards[p->cardCount-1]=cardname; else { p->cards[p->cardCount] = malloc(CARD_NAME_SIZE); @@ -101,20 +102,20 @@ pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { return p; } -void updatecmd(char* cmd, pile **p) { - if (p[PLAYED]->cardCount == 0 ) return; +void updatecmd(char* cmd, pile p, pile parg) { + if (p.cardCount == 0 ) return; strcat(cmd,"( cat ./"); - strcat(cmd,p[PLAYED]->cards[0]); - if(strcmp(p[PLAYEDARGS]->cards[0],"none")!=0) { + strcat(cmd,p.cards[0]); + if(strcmp(parg.cards[0],"none")!=0) { strcat(cmd," "); - strcat(cmd,p[PLAYEDARGS]->cards[0]); + strcat(cmd,parg.cards[0]); } - for (int i=1;i<p[PLAYED]->cardCount;i++) { + for (int i=1;i<p.cardCount;i++) { strcat(cmd," | \n./"); - strcat(cmd,p[PLAYED]->cards[i]); - if(strcmp(p[PLAYEDARGS]->cards[i],"none")!=0) { + strcat(cmd,p.cards[i]); + if(strcmp(parg.cards[i],"none")!=0) { strcat(cmd," "); - strcat(cmd,p[PLAYEDARGS]->cards[i]); + strcat(cmd,parg.cards[i]); } } strcat(cmd," ) 2> /dev/null\n"); @@ -183,7 +184,7 @@ int debug(int l, pile curmenu,struct tb_event ev) { return l; } -int display(pile** piles, pile curmenu, bool selection, char* cmd, char* res, char* intern) { +int display(pile** piles, pile curmenu, bool selection, char* cmd, char* res, char* intern, char* cmdennemy, char* resennemy, char* internennemy) { int lineoffset=0; tb_clear(); @@ -200,7 +201,15 @@ int display(pile** piles, pile curmenu, bool selection, char* cmd, char* res, ch vr(CARD_NAME_SIZE*3,0,max(lineoffset,lo)); - displaypile(*piles[PLAYEDENNEMY], curmenu, CARD_NAME_SIZE*3+2, 0, selection); + lo=displaypile(*piles[PLAYEDENNEMY], curmenu, CARD_NAME_SIZE*3+2, 0, selection); + + vr(CARD_NAME_SIZE*4,0,max(lineoffset,lo)); + + displaypile(*piles[PLAYEDENNEMYARGS], curmenu, CARD_NAME_SIZE*4+2, 0, selection); + + lo=displaytextblock(resennemy,CARD_NAME_SIZE*3+2,lo); + lo=displaytextblock(internennemy,CARD_NAME_SIZE*3+2,lo); + lo=displaytextblock(cmdennemy,CARD_NAME_SIZE*3+2,lo); lineoffset=displaytextblock(res,0,lineoffset); lineoffset=displaytextblock(intern,0,lineoffset); @@ -220,22 +229,23 @@ int main(int argc, char **argv) { tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); struct tb_event ev; - char res[LIST_SIZE]; - char intern[LIST_SIZE]; - FILE *fp2; + char cmd[LIST_SIZE]; char cmdennemy[LIST_SIZE]; + char res[LIST_SIZE]; char resennemy[LIST_SIZE]; + char intern[LIST_SIZE]; char internennemy[LIST_SIZE]; - char cmd[LIST_SIZE]; - cmd[0]='\0'; + FILE *fp2, *fp3; - pile *piles[5]; + pile *piles[6]; pile hand=createpile("hand"); pile played=createpile("played"); pile args=createpile("args"); pile playedargs=createpile("playedargs"); pile playedennemy=createpile("playedennemy"); + pile playedennemyargs=createpile("playedennemyargs"); piles[HAND]=&hand;piles[PLAYED]=&played; piles[ARGS]=&args;piles[PLAYEDARGS]=&playedargs; piles[PLAYEDENNEMY]=&playedennemy; + piles[PLAYEDENNEMYARGS]=&playedennemyargs; file2pile(stdin, &hand, piles); addcardtopile("strike",&playedennemy,piles); @@ -246,10 +256,15 @@ int main(int argc, char **argv) { while(!quit) { cmd[0]='\0';res[0]='\0';intern[0]='\0'; - updatecmd(cmd, piles); + cmdennemy[0]='\0';resennemy[0]='\0';internennemy[0]='\0'; + updatecmd(cmd, played, playedargs); + updatecmd(cmdennemy, playedennemy, playedennemyargs); updateres(res, cmd, fp2); + updateres(resennemy, cmdennemy, fp3); updateinterncmd(intern, played); - int l=display(piles,*curmenu,selection,cmd,res,intern); + updateinterncmd(internennemy, playedennemy); + + int l=display(piles,*curmenu,selection,cmd,res,intern,cmdennemy,resennemy,internennemy); debug(l,*curmenu,ev); tb_present(); tb_poll_event(&ev);