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 f13831414d6305330720acb18bc0deff3da6a77d
parent cff2570609efa4fed3ba1c40a0773883c8bfa372
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Tue, 21 Jan 2025 18:07:21 +0100

Implémentation de l'enum des piles

On peut écrire piles[HAND] plutôt que piles[0]
Mais c'est pas ça qui permet de la bonne facto pour display, prochain
objectif

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

diff --git a/interface.c b/interface.c @@ -18,6 +18,8 @@ typedef struct int curline; } pile; +enum pileid { HAND, PLAYED, ARGS }; + int max(int a, int b) { return a > b ? a : b; } int nblines(char *str) { @@ -64,10 +66,10 @@ pile* moveselection(pile* p, pile** piles, char* direction, bool selection) { p->cards[p->curline+step]=tmp; } p->curline=p->curline+step; - } else { - if (p->name=="hand" && direction == "down") { return piles[2]; } - else if (p->name=="args" && direction == "up") { return piles[0]; } + return p; } + if (p->name=="hand" && direction == "down") { return piles[ARGS]; } + else if (p->name=="args" && direction == "up") { return piles[HAND]; } return p; } @@ -118,48 +120,48 @@ pile file2pile(char* filename) { void display(pile** piles, pile curmenu, bool selection, char* cmd, char* res, char* intern) { tb_clear(); int i; int j; int w; - int biggestpile=max(piles[1]->cardCount,piles[0]->cardCount)+piles[2]->cardCount; - for (i=0;i<piles[0]->cardCount;i++) { - if (i==piles[0]->curline && curmenu.name=="hand") { + int biggestpile=max(piles[PLAYED]->cardCount,piles[HAND]->cardCount)+piles[ARGS]->cardCount; + for (i=0;i<piles[HAND]->cardCount;i++) { + if (i==piles[HAND]->curline && curmenu.name=="hand") { if (selection) { - tb_printf(0, i, TB_BLACK, TB_BLUE, piles[0]->cards[i]); + tb_printf(0, i, TB_BLACK, TB_BLUE, piles[HAND]->cards[i]); } else { - tb_printf(0, i, TB_BLACK, TB_WHITE, piles[0]->cards[i]); + tb_printf(0, i, TB_BLACK, TB_WHITE, piles[HAND]->cards[i]); } } - else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, piles[0]->cards[i]); } + else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, piles[HAND]->cards[i]); } } - for (j=0;j<piles[1]->cardCount;j++) { - if (j==piles[1]->curline && curmenu.name=="played") { + for (j=0;j<piles[PLAYED]->cardCount;j++) { + if (j==piles[PLAYED]->curline && curmenu.name=="played") { if (selection) { - tb_printf(CARD_NAME_SIZE+2, j, TB_BLACK, TB_BLUE, piles[1]->cards[j]); + tb_printf(CARD_NAME_SIZE+2, j, TB_BLACK, TB_BLUE, piles[PLAYED]->cards[j]); } else { - tb_printf(CARD_NAME_SIZE+2, j, TB_BLACK, TB_WHITE, piles[1]->cards[j]); + tb_printf(CARD_NAME_SIZE+2, j, TB_BLACK, TB_WHITE, piles[PLAYED]->cards[j]); } } - else { tb_printf(CARD_NAME_SIZE+2, j, TB_DEFAULT, TB_BLACK, piles[1]->cards[j]); } + else { tb_printf(CARD_NAME_SIZE+2, j, TB_DEFAULT, TB_BLACK, piles[PLAYED]->cards[j]); } } - for (j=0;j<piles[2]->cardCount;j++) { - if (j==piles[2]->curline && curmenu.name=="args") { + for (j=0;j<piles[ARGS]->cardCount;j++) { + if (j==piles[ARGS]->curline && curmenu.name=="args") { if (selection) { - tb_printf(0, biggestpile+j, TB_BLACK, TB_BLUE, piles[2]->cards[j]); + tb_printf(0, biggestpile+j, TB_BLACK, TB_BLUE, piles[ARGS]->cards[j]); } else { - tb_printf(0,biggestpile+j, TB_BLACK, TB_WHITE, piles[2]->cards[j]); + tb_printf(0,biggestpile+j, TB_BLACK, TB_WHITE, piles[ARGS]->cards[j]); } } - else { tb_printf(0,biggestpile+j, TB_DEFAULT, TB_BLACK, piles[2]->cards[j]); } + else { tb_printf(0,biggestpile+j, TB_DEFAULT, TB_BLACK, piles[ARGS]->cards[j]); } } - for (int w=0;w<biggestpile+piles[2]->cardCount;w++) { + for (int w=0;w<biggestpile+piles[ARGS]->cardCount;w++) { tb_printf(CARD_NAME_SIZE,w,TB_DEFAULT, TB_BLACK, "|"); } - tb_printf(0, biggestpile+1+piles[2]->cardCount, TB_DEFAULT, TB_BLACK, cmd); - hr(biggestpile+1+piles[2]->cardCount+piles[1]->cardCount); - tb_printf(0, biggestpile+1+piles[2]->cardCount+piles[1]->cardCount+1+piles[2]->cardCount, TB_DEFAULT, TB_BLACK, res); + tb_printf(0, biggestpile+1+piles[ARGS]->cardCount, TB_DEFAULT, TB_BLACK, cmd); + hr(biggestpile+1+piles[ARGS]->cardCount+piles[PLAYED]->cardCount); + tb_printf(0, biggestpile+1+piles[ARGS]->cardCount+piles[PLAYED]->cardCount+1+piles[ARGS]->cardCount, TB_DEFAULT, TB_BLACK, res); int l=0; l=nblines(res); - hr(biggestpile+1+piles[2]->cardCount+piles[1]->cardCount+1+piles[2]->cardCount+l); - tb_printf(0, biggestpile+1+piles[2]->cardCount+piles[1]->cardCount+2+l, TB_DEFAULT, TB_BLACK, intern); + hr(biggestpile+1+piles[ARGS]->cardCount+piles[PLAYED]->cardCount+1+piles[ARGS]->cardCount+l); + tb_printf(0, biggestpile+1+piles[ARGS]->cardCount+piles[PLAYED]->cardCount+2+l, TB_DEFAULT, TB_BLACK, intern); tb_printf(0,30,TB_DEFAULT,TB_DEFAULT,curmenu.name); char str[100];sprintf(str,"%d",curmenu.cardCount); tb_printf(0,31,TB_DEFAULT,TB_DEFAULT,str); @@ -181,7 +183,7 @@ int main(int argc, char **argv) { pile played=createpile("played"); pile args=createpile("args"); pile *piles[3]; - piles[0]=&hand;piles[1]=&played;piles[2]=&args; + piles[HAND]=&hand;piles[PLAYED]=&played;piles[ARGS]=&args; bool selection=false; bool quit=false;