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 f26d609d963b859a3dc62f64fd2430e7cc6b3826
parent ff888c70134174a3c2d8f07901793c5f0b0fa469
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Tue, 21 Jan 2025 16:42:43 +0100

curmenu est un pointeur vers la pile courante

Bien pour factoriser certains trucs mais ça casse le passage de hand
vers args et je sais pas trop comment appréhender la suite

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

diff --git a/interface.c b/interface.c @@ -52,7 +52,7 @@ void removecardofpile(int cardposition, pile* p) { if (p->curline>0) { p->curline--; } } -char* moveselection(pile* p, char *curmenu, char* direction, bool selection) { +char* moveselection(pile* p, char* direction, bool selection) { int step; if (direction == "up") { step = -1; } else { step = 1; } @@ -65,10 +65,9 @@ char* moveselection(pile* p, char *curmenu, char* direction, bool selection) { } p->curline=p->curline+step; } else { - if(curmenu=="hand" && direction == "down") { curmenu="args"; } - else if (curmenu=="args" && direction == "up") { curmenu="hand"; } + if(p->name=="hand" && direction == "down") { return "args"; } + else if (p->name=="args" && direction == "up") { return "hand"; } } - return curmenu; } void updatecmd(char* cmd, const pile p) { @@ -115,12 +114,12 @@ pile file2pile(char* filename) { } -void display(pile* h, pile* p, pile* a, char* curmenu, bool selection, char* cmd, char* res, char* intern) { +void display(pile* h, pile* p, pile* a, pile* curmenu, bool selection, char* cmd, char* res, char* intern) { tb_clear(); int i; int j; int w; int biggestpile=max(p->cardCount,h->cardCount)+a->cardCount; for (i=0;i<h->cardCount;i++) { - if (i==h->curline && curmenu=="hand") { + if (i==h->curline && curmenu->name=="hand") { if (selection) { tb_printf(0, i, TB_BLACK, TB_BLUE, h->cards[i]); } else { @@ -130,7 +129,7 @@ void display(pile* h, pile* p, pile* a, char* curmenu, bool selection, char* cmd else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, h->cards[i]); } } for (j=0;j<p->cardCount;j++) { - if (j==p->curline && curmenu=="played") { + if (j==p->curline && curmenu->name=="played") { if (selection) { tb_printf(CARD_NAME_SIZE+2, j, TB_BLACK, TB_BLUE, p->cards[j]); } else { @@ -140,7 +139,7 @@ void display(pile* h, pile* p, pile* a, char* curmenu, bool selection, char* cmd else { tb_printf(CARD_NAME_SIZE+2, j, TB_DEFAULT, TB_BLACK, p->cards[j]); } } for (j=0;j<a->cardCount;j++) { - if (j==a->curline && curmenu=="args") { + if (j==a->curline && curmenu->name=="args") { if (selection) { tb_printf(0, biggestpile+j, TB_BLACK, TB_BLUE, a->cards[j]); } else { @@ -160,7 +159,7 @@ void display(pile* h, pile* p, pile* a, char* curmenu, bool selection, char* cmd 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_printf(0,30,TB_DEFAULT,TB_DEFAULT,curmenu->name); tb_present(); } @@ -181,7 +180,7 @@ int main(int argc, char **argv) { bool selection=false; bool quit=false; - char* curmenu="hand"; + pile *curmenu=&hand; tb_init(); @@ -195,43 +194,31 @@ int main(int argc, char **argv) { switch(ev.key) { /* up */ case 65517: - if (curmenu=="hand") { - curmenu=moveselection(&hand,curmenu,"up",selection); - } else if (curmenu=="args") { - curmenu=moveselection(&args,curmenu,"up",selection); - } else if (curmenu=="played") { - curmenu=moveselection(&played,curmenu,"up",selection); - } + char *nextmenu=moveselection(curmenu,"up",selection); break; /* down */ case 65516: - if (curmenu=="hand") { - curmenu=moveselection(&hand,curmenu,"down",selection); - } else if (curmenu=="args") { - curmenu=moveselection(&args,curmenu,"down",selection); - } else if (curmenu=="played") { - curmenu=moveselection(&played,curmenu,"down",selection); - } + moveselection(curmenu,"down",selection); break; /* <- */ case 65515: - if (curmenu=="played") { + if (curmenu->name=="played") { if (selection) { addcardtopile(played.cards[played.curline],&hand); removecardofpile(played.curline,&played); selection=!selection; } - curmenu="hand"; + curmenu=&hand; } break; /* -> */ case 65514: - if (curmenu=="hand") { + if (curmenu->name=="hand") { if (selection) { addcardtopile(hand.cards[hand.curline],&played); removecardofpile(hand.curline,&hand); } - curmenu="played"; + curmenu=&played; } break; case 13: