Compare commits

...

2 Commits

Author SHA1 Message Date
d07587c654 finalisation de la selection 2025-06-12 13:33:05 +02:00
6cb6b2f71a déplacement sur blanc corrects 2025-06-12 13:21:22 +02:00

19
main.c
View File

@ -2,6 +2,7 @@
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <locale.h> #include <locale.h>
#include <stdlib.h>
#define FG_DEFAULT_BG_WHITE "\x1b[30;48;5;255m" #define FG_DEFAULT_BG_WHITE "\x1b[30;48;5;255m"
#define FG_DEFAULT_BG_136 "\x1b[30;48;5;136m" #define FG_DEFAULT_BG_136 "\x1b[30;48;5;136m"
@ -111,7 +112,7 @@ int print_tab() {
return 0; return 0;
} }
int piece_selection() { void piece_selection() {
if (y % 2 == 1) { if (y % 2 == 1) {
if (x % 2 == 0) { if (x % 2 == 0) {
@ -129,12 +130,10 @@ int piece_selection() {
printf(FG_DEFAULT_BG_136"\x1b[%d;%dH%s", y - y_direction + 1 , (x - x_direction) * 2 + 1, piece_to_str(board[y - y_direction][x - x_direction])); printf(FG_DEFAULT_BG_136"\x1b[%d;%dH%s", y - y_direction + 1 , (x - x_direction) * 2 + 1, piece_to_str(board[y - y_direction][x - x_direction]));
} }
} }
printf("\x1b[%d;%dH\x1b[39;106m%s", y + 1 , x * 2 + 1, piece_to_str(board[y][x]));
printf("\x1b[%d;%dH\x1b[39;49ma", y + 1 , x * 2 + 1);
} }
int controls() { void controls() {
piece_selection(); piece_selection();
@ -159,7 +158,7 @@ int controls() {
} }
break; break;
case 106: // j case 106: // j
if (y < 7 && (piece_color[y][x - 1] == 1 || piece_color[y][x - 1] == 2)) { if (y < 7 && (piece_color[y + 1][x] == 1 || piece_color[y + 1][x] == 2)) {
y++; y++;
y_direction++; y_direction++;
piece_selection(); piece_selection();
@ -171,7 +170,7 @@ int controls() {
} }
break; break;
case 107: // k case 107: // k
if (y > 6 && (piece_color[y][x - 1] == 1 || piece_color[y][x - 1] == 2)) { if (y > 6 && (piece_color[y - 1][x] == 1 || piece_color[y - 1][x] == 2)) {
y--; y--;
y_direction = -1; y_direction = -1;
piece_selection(); piece_selection();
@ -183,7 +182,7 @@ int controls() {
} }
break; break;
case 108: // l case 108: // l
if (x < 7 && (piece_color[y][x - 1] == 1 || piece_color[y][x - 1] == 2)) { if (x < 7 && (piece_color[y][x + 1] == 1 || piece_color[y][x + 1] == 2)) {
x++; x++;
x_direction++; x_direction++;
piece_selection(); piece_selection();
@ -194,10 +193,12 @@ int controls() {
piece_selection(); piece_selection();
} }
break; break;
case 113:
printf("\x1b[?25h");
exit(0);
default: break; default: break;
} }
} }
return 0;
} }
int main() { int main() {