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 8440a1227328a92ccee16d7989bb83e720693b7c parent 99c19a81e3cb23a74b64f7d0f124eab79a7ddc11 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Tue, 21 Jan 2025 15:16:35 +0100 Début d'implémentation des arguments Pour le moment on peut simplement appuyer sur m et créer un argument Problèmes : * casse l'affichage des commandes et résultats * on peut rien faire avec * on peut ajouter en argument des trucs qui ne devraient pas l'être * il faudrait factoriser cette histoire de moveselection etc, c'est vraiment crâde là * sûrement plein d'autres choses Diffstat:
M | interface.c | | | 59 | +++++++++++++++++++++++++++++++++++++++++------------------ |
1 file changed, 41 insertions(+), 18 deletions(-)
diff --git a/interface.c b/interface.c @@ -51,7 +51,7 @@ void removecardofpile(int cardposition, pile* p) { if (p->curline>0) { p->curline--; } } -void moveselection(pile* p, char* direction, bool selection) { +char* moveselection(pile* p, char *curmenu, char* direction, bool selection) { int step; if (direction == "up") { step = -1; } else { step = 1; } @@ -63,7 +63,11 @@ void moveselection(pile* p, char* direction, bool selection) { p->cards[p->curline+step]=tmp; } p->curline=p->curline+step; + } else { + if(curmenu=="hand" && direction == "down") { curmenu="args"; } + else if (curmenu=="args" && direction == "up") { curmenu="hand"; } } + return curmenu; } void updatecmd(char* cmd, const pile p) { @@ -109,10 +113,10 @@ pile file2pile(FILE *fp) { } -void display(pile* h, pile* p, char* curmenu, bool selection, char* cmd, char* res, char* intern) { +void display(pile* h, pile* p, pile* a, char* curmenu, bool selection, char* cmd, char* res, char* intern) { tb_clear(); int i; int j; int w; - int biggestpile=max(p->cardCount,h->cardCount); + int biggestpile=max(p->cardCount,h->cardCount)+a->cardCount; for (i=0;i<h->cardCount;i++) { if (i==h->curline && curmenu=="hand") { if (selection) { @@ -123,9 +127,6 @@ void display(pile* h, pile* p, char* curmenu, bool selection, char* cmd, char* r } else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, h->cards[i]); } } - for (int w=0;w<biggestpile;w++) { - tb_printf(CARD_NAME_SIZE,w,TB_DEFAULT, TB_BLACK, "|"); - } for (j=0;j<p->cardCount;j++) { if (j==p->curline && curmenu=="played") { if (selection) { @@ -136,13 +137,28 @@ void display(pile* h, pile* p, char* curmenu, bool selection, char* cmd, char* r } else { tb_printf(CARD_NAME_SIZE+2, j, TB_DEFAULT, TB_BLACK, p->cards[j]); } } - int l=0; - l=nblines(res); - tb_printf(0, biggestpile+1, TB_DEFAULT, TB_BLACK, cmd); - hr(biggestpile+1+p->cardCount); - tb_printf(0, biggestpile+1+p->cardCount+1, TB_DEFAULT, TB_BLACK, res); - hr(biggestpile+1+p->cardCount+1+l); - tb_printf(0, biggestpile+1+p->cardCount+2+l, TB_DEFAULT, TB_BLACK, intern); + for (j=0;j<a->cardCount;j++) { + if (j==a->curline && curmenu=="args") { + if (selection) { + tb_printf(0, biggestpile+j, TB_BLACK, TB_BLUE, a->cards[j]); + } else { + tb_printf(0,biggestpile+j, TB_BLACK, TB_WHITE, a->cards[j]); + } + } + else { tb_printf(0,biggestpile+j, TB_DEFAULT, TB_BLACK, a->cards[j]); } + } + + for (int w=0;w<biggestpile+a->cardCount;w++) { + tb_printf(CARD_NAME_SIZE,w,TB_DEFAULT, TB_BLACK, "|"); + } + + tb_printf(0, biggestpile+1+a->cardCount, TB_DEFAULT, TB_BLACK, cmd); + hr(biggestpile+1+a->cardCount+p->cardCount); + tb_printf(0, biggestpile+1+a->cardCount+p->cardCount+1+a->cardCount, TB_DEFAULT, TB_BLACK, res); + int l=0; l=nblines(res); + hr(biggestpile+1+a->cardCount+p->cardCount+1+a->cardCount+l); + tb_printf(0, biggestpile+1+a->cardCount+p->cardCount+2+l, TB_DEFAULT, TB_BLACK, intern); + tb_printf(0,30,TB_DEFAULT,TB_DEFAULT,curmenu); tb_present(); } @@ -160,6 +176,7 @@ int main(int argc, char **argv) { pile hand=file2pile(fp); pile played=createpile(); + pile args=createpile(); bool selection=false; bool quit=false; @@ -172,23 +189,27 @@ int main(int argc, char **argv) { updatecmd(cmd, played); updateres(res, cmd, fp2); updateinterncmd(intern, played); - display(&hand,&played,curmenu,selection,cmd,res,intern); + display(&hand,&played,&args,curmenu,selection,cmd,res,intern); tb_poll_event(&ev); switch(ev.key) { /* up */ case 65517: if (curmenu=="hand") { - moveselection(&hand,"up",selection); + curmenu=moveselection(&hand,curmenu,"up",selection); + } else if (curmenu=="args") { + curmenu=moveselection(&args,curmenu,"up",selection); } else if (curmenu=="played") { - moveselection(&played,"up",selection); + curmenu=moveselection(&played,curmenu,"up",selection); } break; /* down */ case 65516: if (curmenu=="hand") { - moveselection(&hand,"down",selection); + curmenu=moveselection(&hand,curmenu,"down",selection); + } else if (curmenu=="args") { + curmenu=moveselection(&args,curmenu,"down",selection); } else if (curmenu=="played") { - moveselection(&played,"down",selection); + curmenu=moveselection(&played,curmenu,"down",selection); } break; /* <- */ @@ -220,6 +241,8 @@ int main(int argc, char **argv) { case 113: quit=true; break; + case 109: + addcardtopile(res,&args); default: break; }