From 996fa89a7c352c1f219b28c09f3ef681e6c205fe Mon Sep 17 00:00:00 2001 From: alberr_b0yyy Date: Thu, 12 Jun 2025 15:45:26 +0200 Subject: [PATCH] je dois partir --- main.c | 82 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/main.c b/main.c index 969caef..93baf98 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #define FG_DEFAULT_BG_WHITE "\x1b[30;48;5;255m" #define FG_DEFAULT_BG_136 "\x1b[30;48;5;136m" @@ -48,7 +49,7 @@ char* piece_to_str(const Pieces piece) { } } -int piece_color_to_str(Pieces piece) { +int piece_color_to_int(Pieces piece) { switch (piece) { case EMPTY: return 3; case BLACK_PAWN: @@ -83,7 +84,7 @@ int x = 0; int y = 7; int x_direction = 0; int y_direction = 0; - +bool player_track = true; ////////////////////////////////////////// @@ -112,7 +113,7 @@ int print_tab() { return 0; } -void piece_selection() { +void tile_selection() { if (y % 2 == 1) { if (x % 2 == 0) { @@ -133,10 +134,26 @@ void piece_selection() { printf("\x1b[%d;%dH\x1b[39;106m%s", y + 1 , x * 2 + 1, piece_to_str(board[y][x])); } -void controls() { - piece_selection(); +void a() { + if (board[y][x] == WHITE_PAWN || board[y][x] == BLACK_PAWN) { + printf("\x1b[%d;%dH\x1b[96;106m\u2800\u2800", y - 1 + 1 , x * 2 + 1); + printf("\x1b[%d;%dH\x1b[96;106m\u2800\u2800", y - 2 + 1 , x * 2 + 1); + if (piece_color_to_int(board[y - 1][x - 1]) == 1 || piece_color_to_int(board[y - 1][x + 1]) == 2) { + printf("\x1b[%d;%dH\x1b[91;101m\u2800\u2800", y - 1 + 1 , x * 2 + 2 + 1); + } + if (piece_color_to_int(board[y + 1][x - 1]) == 1 || piece_color_to_int(board[y - 1][x - 1]) == 2) { + printf("\x1b[%d;%dH\x1b[91;101m\u2800\u2800", y - 1 + 1 , x * 2 - 2 + 1); + } + } + + +} + +void controls() { + tile_selection(); + while (1) { x_direction = 0; @@ -146,54 +163,29 @@ void controls() { switch (input) { case 104: // h - if (x > 0 && (piece_color[y][x - 1] == 1 || piece_color[y][x - 1] == 2)) { - x--; - x_direction--; - piece_selection(); - } - else { - x = 7; - x_direction = 7; - piece_selection(); - } - break; case 106: // j - if (y < 7 && (piece_color[y + 1][x] == 1 || piece_color[y + 1][x] == 2)) { - y++; - y_direction++; - piece_selection(); - } - else { - y = 6; - y_direction--; - piece_selection(); - } - break; case 107: // k - if (y > 6 && (piece_color[y - 1][x] == 1 || piece_color[y - 1][x] == 2)) { - y--; - y_direction = -1; - piece_selection(); + if (y >= 0) { + for (int i = y; i < 8; ++i) { + if (piece_color[y][x] == 1 || piece_color[y][x] == 2) { + break; + } + y--; + y_direction--; + } } else { y = 7; y_direction = 1; - piece_selection(); } - break; + tile_selection(); case 108: // l - if (x < 7 && (piece_color[y][x + 1] == 1 || piece_color[y][x + 1] == 2)) { - x++; - x_direction++; - piece_selection(); - } - else { - x = 0; - x_direction = -7; - piece_selection(); - } + + + case 13: // enter + a(); break; - case 113: + case 113: // q printf("\x1b[?25h"); exit(0); default: break; @@ -212,7 +204,7 @@ int main() { for (int y = 0; y < 8; ++y) { for (int x = 0; x < 8; ++x) { - piece_color[y][x] = piece_color_to_str(board[y][x]); + piece_color[y][x] = piece_color_to_int(board[y][x]); } }