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 e380a95af136214c428a186c6de60b8cfa95c8a1
parent 8e70bf60b5d75c06d3db405026e21234177fa30b
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 29 Jan 2025 16:16:34 +0100

On suit les coordonnées des piles pour la souris

Maintenant y'a dans les piles begin et end qui sont les coordos de la
pile.
Ca permet de faire fonctionner la souris

Bug connu : un souci avec le passage dans la pile args

A faire : drag and drop ???

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

diff --git a/interface.c b/interface.c @@ -11,17 +11,19 @@ #define CARD_NAME_SIZE 25 typedef struct { + int x; + int y; +} coord; + +typedef struct { char *name; int cardCount; char **cards; int curline; + coord begin; + coord end; } pile; -typedef struct { - int x; - int y; -} coord; - enum pileid { HAND, PLAYED, ARGS, PLAYEDARGS, PLAYEDENNEMY, PLAYEDENNEMYARGS }; int max(int a, int b) { return a > b ? a : b; } @@ -172,14 +174,16 @@ coord displaybox(int coloffset, int lineoffset, int width, int length) { return p; } -coord displaypile(pile p, pile curmenu, int coloffset, int lineoffset, bool selection) { +coord displaypile(pile *p, pile curmenu, int coloffset, int lineoffset, bool selection) { int newlineoffset=lineoffset; - int maxwidth=CARD_NAME_SIZE+2; int maxlen=p.cardCount+1; - coord point=displaybox(coloffset,lineoffset,maxwidth,maxlen); + int maxwidth=CARD_NAME_SIZE+2; int maxlen=p->cardCount+1; + coord begin; begin.x=coloffset; begin.y=lineoffset; + coord end=displaybox(begin.x,begin.y,maxwidth,maxlen); + p->begin=begin; p->end=end; coloffset++;lineoffset++; - for (int i=0;i<p.cardCount;i++) { - char *name = strcmp(p.cards[i],"none")==0 ? " " : p.cards[i] ; - if (i==p.curline && p.name == curmenu.name ) { + for (int i=0;i<p->cardCount;i++) { + char *name = strcmp(p->cards[i],"none")==0 ? " " : p->cards[i] ; + if (i==p->curline && p->name == curmenu.name ) { int background = selection ? TB_BLUE : TB_WHITE ; tb_printf(coloffset, lineoffset+i, TB_BLACK, background, name); } @@ -187,7 +191,7 @@ coord displaypile(pile p, pile curmenu, int coloffset, int lineoffset, bool sele tb_printf(coloffset, lineoffset+i, TB_DEFAULT, TB_DEFAULT, name); newlineoffset++; } - return point; + return end; } coord displaytextblock(char *text, int coloffset, int lineoffset) { @@ -216,12 +220,12 @@ int display(pile** piles, pile curmenu, bool selection, char* cmd, char* res, ch coord p; tb_clear(); - p=displaypile(*piles[PLAYEDARGS], curmenu, 0, 0, selection); - coord p2=displaypile(*piles[PLAYED], curmenu, p.x, 0, selection); - coord p3=displaypile(*piles[HAND], curmenu, p2.x, 0, selection); - coord p4=displaypile(*piles[ARGS], curmenu, p2.x, p3.y, selection); - coord p5=displaypile(*piles[PLAYEDENNEMY], curmenu, p3.x, 0, selection); - coord p6=displaypile(*piles[PLAYEDENNEMYARGS], curmenu, p5.x, 0, selection); + p=displaypile(piles[PLAYEDARGS], curmenu, 0, 0, selection); + coord p2=displaypile(piles[PLAYED], curmenu, p.x, 0, selection); + coord p3=displaypile(piles[HAND], curmenu, p2.x, 0, selection); + coord p4=displaypile(piles[ARGS], curmenu, p2.x, p3.y, selection); + coord p5=displaypile(piles[PLAYEDENNEMY], curmenu, p3.x, 0, selection); + coord p6=displaypile(piles[PLAYEDENNEMYARGS], curmenu, p5.x, 0, selection); int m=max(max(p2.y,p4.y),p5.y); p=displaytextblock(res,0,m+2); @@ -385,9 +389,12 @@ int main(int argc, char **argv) { case 3: /*Mouse*/ switch(ev.key) { case 65512: /*MouseLeft*/ - if(ev.x<CARD_NAME_SIZE && ev.y<hand.cardCount) { - curmenu=&hand; - curmenu->curline=ev.y; + for(int i=0;i<6;i++) { + if( piles[i]->begin.x < ev.x && ev.x < piles[i]->end.x \ + && piles[i]->begin.y < ev.y && ev.y < piles[i]->end.y ) { + curmenu=piles[i]; + curmenu->curline=ev.y-1; + } } break; case 65508: /*MouseWheelUp*/