netoyage du code et suppression des x/y_direction

This commit is contained in:
alberr_b0yyy 2025-06-20 15:39:27 +02:00
parent 4096dd9f1d
commit 0641473091

52
main.c
View File

@ -77,8 +77,6 @@ Pieces board[8][8] = {
int piece_color[8][8];
int x = 0;
int y = 7;
int x_direction = 0;
int y_direction = 0;
bool player_track = true;
//////////////////////////////////////////
@ -132,7 +130,7 @@ void a() {
if (board[y][x] == WHITE_PAWN) {
if (piece_color_to_int(board[y - 1][x]) == 3) {
printf("\x1b[%d;%dH\x1b[96;106m\u2800\u2800", y - 1 + 1 , x * 2 + 1);
if (piece_color_to_int(board[y - 1][x]) == 3) {
if (piece_color_to_int(board[y - 2][x]) == 3) {
printf("\x1b[%d;%dH\x1b[96;106m\u2800\u2800", y - 2 + 1 , x * 2 + 1);
}
}
@ -153,168 +151,129 @@ void controls() {
while (1) {
tile_selection();
x_direction = 0;
y_direction = 0;
switch (getchar()) {
case 104: // h
if (x == 0) {
if (y > 0) {
y--;
y_direction--;
}
else if (y == 0) {
y = 7;
y_direction = 7;
}
x = 7;
x_direction = 7;
}
else if (x > 0) {
x--;
x_direction--;
while (piece_color_to_int(board[y][x]) == 3) {
if (x == 0) {
if (y > 0) {
y--;
y_direction--;
}
else if (y == 0) {
y = 7;
y_direction = 7;
}
x = 7;
x_direction = 7;
break;
}
x--;
x_direction--;
}
}
while (piece_color_to_int(board[y][x]) == 3) {
x--;
x_direction--;
}
break;
case 106: // j
if (y == 7) {
if (x < 7) {
x++;
x_direction++;
}
else if (x == 7) {
x = 0;
x_direction = -7;
}
y = 0;
y_direction = -7;
}
else if (y < 7) {
y++;
y_direction++;
while (piece_color_to_int(board[y][x]) == 3) {
if (y == 7) {
if (x < 7) {
x++;
x_direction++;
}
else if (x == 7) {
x = 0;
x_direction = -7;
}
y = 0;
y_direction = -7;
break;
}
y++;
y_direction++;
}
}
while (piece_color_to_int(board[y][x]) == 3) {
y++;
y_direction++;
}
break;
case 107: // k
if (y == 0) {
if (x > 0) {
x--;
x_direction--;
}
else if (x == 0) {
x = 7;
x_direction = 7;
}
y = 7;
y_direction = 7;
}
else if (y > 0) {
y--;
y_direction--;
while (piece_color_to_int(board[y][x]) == 3) {
if (y == 0) {
if (x > 0) {
x--;
x_direction--;
}
else if (x == 0) {
x = 7;
x_direction = 7;
}
y = 7;
y_direction = 7;
break;
}
y--;
y_direction--;
}
}
while (piece_color_to_int(board[y][x]) == 3) {
y--;
y_direction--;
}
break;
case 108: // l
if (x == 7) {
if (y < 7) {
y++;
y_direction++;
}
else if (y == 7) {
y = 0;
y_direction = -7;
}
x = 0;
x_direction = -7;
}
else if (x < 7) {
x++;
x_direction++;
while (piece_color_to_int(board[y][x]) == 3) {
if (x == 7) {
if (y < 7) {
y++;
y_direction++;
}
else if (y == 7) {
y = 0;
y_direction = -7;
}
x = 0;
x_direction = -7;
break;
}
x++;
x_direction++;
}
}
while (piece_color_to_int(board[y][x]) == 3) {
x++;
x_direction++;
}
break;
case 10: // enter
//a();
a();
break;
case 113: // q
return;
@ -325,7 +284,6 @@ void controls() {
int main() {
struct termios t_old, t_new;
tcgetattr(STDIN_FILENO, &t_old);
t_new = t_old;
t_new.c_lflag &= ~(ICANON | ECHO);
@ -333,14 +291,10 @@ int main() {
setbuf(stdout, NULL);
setlocale(LC_ALL, "en_US.UTF-8");
printf("\x1b[H\x1b[J");
printf("\x1b[?25l");
print_tab();
printf("\x1b[H\x1b[J\x1b[?25l");
controls();
printf("\x1b[10;0H\x1b[0m\x1b[?25h");
tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
return 0;