Une TUI pour jouer au go - retour accueil
git clone git://bebou.netlib.re/go-tui
Log | Files | Refs |
commit 0f48b62eaf9c717ec22d4ad6f228b606c71646e5 parent 11389e954bed5f130ab584e6f19b27540a344e05 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Tue, 15 Jul 2025 19:35:41 +0200 On suppr avec MOUSE1 et ça garde la couleur Diffstat:
M | gotui.c | | | 38 | +++++++++++++++++++------------------- |
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/gotui.c b/gotui.c @@ -20,11 +20,21 @@ struct stone create_stone(int x, int y, int color) { return s; } +int spot_is_taken(struct stone* stone_list, int stone_count, int x, int y) { + for (int i=0;i<stone_count;i++) { + if (stone_list[i].x==x && stone_list[i].y==y) + return i; + } + return -1; +} + /*Helper functions*/ int rd(int min, int max) { return (rand()%(max-min+1))+min; } int remain(int a, int b) { return ((a%b)+b)%b; } +/*Display functions*/ + void print_line(int y) { if (y==0) { tb_print(0,y,0,0,"┌"); @@ -47,7 +57,6 @@ void print_line(int y) { } } -/*Display functions*/ void display(struct stone* stone_list, int count, int color) { for (int i=0;i<BOARD_SIZE;i++) @@ -58,14 +67,6 @@ void display(struct stone* stone_list, int count, int color) { } } -int spot_is_taken(struct stone* stone_list, int stone_count, int x, int y) { - for (int i=0;i<stone_count;i++) { - if (stone_list[i].x==x && stone_list[i].y==y) - return 1; - } - return 0; -} - int main(int argc, char **argv) { int input=0; tb_init(); @@ -86,23 +87,22 @@ int main(int argc, char **argv) { else if (ev.key!=0) input=ev.key; struct stone s; + int spot=-1; switch(input) { case 65512: /*MouseLeft*/ - if( ev.x<0 || ev.x>BOARD_SIZE*2+2 || ev.x <0 || ev.y>BOARD_SIZE-1 || ev.x%2 || spot_is_taken(stone_list,stone_count,ev.x,ev.y)) break; + if(ev.x<0 || ev.x>BOARD_SIZE*2+2 || ev.x <0 || ev.y>BOARD_SIZE-1 || ev.x%2) break; + spot=spot_is_taken(stone_list,stone_count,ev.x,ev.y); + if(spot!=-1) { + for (int j=spot;j<stone_count;j++) stone_list[j]=stone_list[j+1]; + stone_count--; + if(color==BLACK) { color=WHITE; } else { color=BLACK; } + break; + } s=create_stone(ev.x,ev.y,color); stone_list[stone_count]=s; stone_count++; if(color==BLACK) { color=WHITE; } else { color=BLACK; } break; - case 65511: /*MouseRight*/ - for (int i=0;i<stone_count;i++) { - if (ev.x==stone_list[i].x && ev.y==stone_list[i].y) { - for (int j=i;j<stone_count;j++) stone_list[j]=stone_list[j+1]; - stone_count--; - break; - } - } - break; case 113: tb_shutdown(); return 0;