Une TUI pour jouer au go - retour accueil
git clone git://bebou.netlib.re/go-tui
Log | Files | Refs |
commit 5e47a878a5ff82d1449512337f83c3769698ffb4 parent d49ad20fd8c3ffedf67b51dac39989fa87300a77 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Tue, 15 Jul 2025 18:43:51 +0200 On peut paramétrer la taille en recompilant Diffstat:
M | gotui.c | | | 34 | ++++++++++++++++++++++++++++------ |
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/gotui.c b/gotui.c @@ -2,9 +2,7 @@ #include "termbox2.h" #include <stdbool.h> -#define TAIL 100 -#define MAX_CAR_NUMBER 3 -#define NB_DEFAULT_PLAYERS 2 +#define BOARD_SIZE 9 enum color { WHITE, BLACK }; @@ -27,10 +25,32 @@ struct stone create_stone(int x, int y, int color) { int rd(int min, int max) { return (rand()%(max-min+1))+min; } int remain(int a, int b) { return ((a%b)+b)%b; } +void print_line(int y) { + if (y==0) { + tb_print(0,y,0,0,"┌"); + tb_print(BOARD_SIZE*2+1,y,0,0,"─┐"); + for (int i=0;i<BOARD_SIZE;i++) { + tb_print(i*2+1,y,0,0,"─┬"); + } + } else if (y>0 && y<BOARD_SIZE-1) { + tb_print(0,y,0,0,"├"); + tb_print(BOARD_SIZE*2+1,y,0,0,"─┤"); + for (int i=0;i<BOARD_SIZE;i++) { + tb_print(i*2+1,y,0,0,"─┼"); + } + } else if (y==BOARD_SIZE-1) { + tb_print(0,y,0,0,"└"); + tb_print(BOARD_SIZE*2+1,y,0,0,"─┘"); + for (int i=0;i<BOARD_SIZE;i++) { + tb_print(i*2+1,y,0,0,"─┴"); + } + } +} + /*Display functions*/ void display(struct stone* stone_list, int count, int color) { - tb_print(0,0,0,0,"\ + /*tb_print(0,0,0,0,"\ ┌─┬─┬─┬─┬─┬─┬─┬─┬─┐\n\ ├─┼─┼─┼─┼─┼─┼─┼─┼─┤\n\ ├─┼─┼─┼─┼─┼─┼─┼─┼─┤\n\ @@ -39,7 +59,9 @@ void display(struct stone* stone_list, int count, int color) { ├─┼─┼─┼─┼─┼─┼─┼─┼─┤\n\ ├─┼─┼─┼─┼─┼─┼─┼─┼─┤\n\ ├─┼─┼─┼─┼─┼─┼─┼─┼─┤\n\ -└─┴─┴─┴─┴─┴─┴─┴─┴─┘"); +└─┴─┴─┴─┴─┴─┴─┴─┴─┘");*/ + for (int i=0;i<BOARD_SIZE;i++) + print_line(i); for(int i=0;i<count;i++) { if(stone_list[i].color==BLACK) tb_printf(stone_list[i].x,stone_list[i].y,0,0,"○"); else tb_printf(stone_list[i].x,stone_list[i].y,0,0,"●"); @@ -79,7 +101,7 @@ int main(int argc, char **argv) { struct stone s; switch(input) { case 65512: /*MouseLeft*/ - if( ev.x<0 || ev.x>9*2 || ev.x <0 || ev.y>8 || ev.x%2 || spot_is_taken(stone_list,stone_count,ev.x,ev.y)) break; + if( ev.x<0 || ev.x>BOARD_SIZE*2 || ev.x <0 || ev.y>BOARD_SIZE-1 || ev.x%2 || spot_is_taken(stone_list,stone_count,ev.x,ev.y)) break; s=create_stone(ev.x,ev.y,color); stone_list[stone_count]=s; stone_count++;