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 99c19a81e3cb23a74b64f7d0f124eab79a7ddc11
parent c580495fe92706ee86d1ff035cef98e53a21ea64
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Tue, 21 Jan 2025 13:33:36 +0100

Fonction pour créer une pile

Factorisation

Diffstat:
Minterface.c | 26++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/interface.c b/interface.c @@ -29,6 +29,13 @@ void hr(int i) { tb_printf(0, i, TB_DEFAULT, TB_BLACK, "-------"); } +pile createpile() { + pile p; + p.cards=malloc(LIST_SIZE); + p.cardCount=0; p.curline=0; + return p; +} + void addcardtopile(char* cardname, pile* p) { p->cards[p->cardCount] = malloc(CARD_NAME_SIZE); strcpy(p->cards[p->cardCount], cardname); @@ -90,17 +97,15 @@ void updateres(char *res, const char *cmd, FILE *fp) { } pile file2pile(FILE *fp) { - pile pi; - pi.cardCount=0; - pi.curline=0; - pi.cards = malloc(LIST_SIZE); + pile p=createpile(); char line[CARD_NAME_SIZE]; while (fgets(line, sizeof(line), fp)) { /* Retire le retour à la ligne à la fin de line */ line[strcspn(line, "\n")] = '\0'; - addcardtopile(line, &pi); + addcardtopile(line, &p); } - return pi; + p.curline=0; + return p; } @@ -154,17 +159,14 @@ int main(int argc, char **argv) { cmd[0]='\0'; pile hand=file2pile(fp); - hand.curline=0; - pile played; - played.cards=malloc(LIST_SIZE); - played.cardCount=0; - played.curline=0; + pile played=createpile(); - tb_init(); bool selection=false; bool quit=false; char* curmenu="hand"; + tb_init(); + while(!quit) { cmd[0]='\0';res[0]='\0';intern[0]='\0'; updatecmd(cmd, played);