JE DOIS PArtir
This commit is contained in:
parent
2c71b39e12
commit
63ccaf6a12
85
main.c
85
main.c
@ -7,6 +7,8 @@
|
||||
|
||||
#define FG_DEFAULT_BG_WHITE "\x1b[30;48;5;255m"
|
||||
#define FG_DEFAULT_BG_136 "\x1b[30;48;5;136m"
|
||||
#define FG_RED_BG_RED "\x1b[31;41m"
|
||||
#define FG_CYAN_BG_CYAN "\x1b[36;46m"
|
||||
|
||||
typedef enum {
|
||||
EMPTY,
|
||||
@ -109,19 +111,42 @@ void print_tab() {
|
||||
void tile_selection() {
|
||||
print_tab();
|
||||
printf("\x1b[%d;%dH\x1b[39;106m%s", y + 1 , x * 2 + 1, piece_to_str(board[y][x]));
|
||||
printf("\x1b[0m");
|
||||
}
|
||||
|
||||
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 (board[y][x] == BLACK_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) {
|
||||
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) {
|
||||
printf(FG_CYAN_BG_CYAN"\x1b[%d;%dH\u2800\u2800", y - 1 + 1 , x * 2 + 2 + 1);
|
||||
}
|
||||
if (piece_color_to_int(board[y + 1][x - 1]) == 1) {
|
||||
printf(FG_CYAN_BG_CYAN"\x1b[%d;%dH\u2800\u2800", y - 1 + 1 , x * 2 - 2 + 1);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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]) == 2) {
|
||||
printf(FG_CYAN_BG_CYAN"\x1b[%d;%dH\u2800\u2800", y - 1 + 1 , x * 2 + 2 + 1);
|
||||
}
|
||||
if (piece_color_to_int(board[y - 1][x - 1]) == 2) {
|
||||
printf(FG_CYAN_BG_CYAN"\x1b[%d;%dH\u2800\u2800", y - 1 + 1 , x * 2 - 2 + 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\x1b[10;0H");
|
||||
}
|
||||
while (1){}
|
||||
}
|
||||
|
||||
void controls() {
|
||||
@ -135,6 +160,12 @@ void controls() {
|
||||
|
||||
switch (input) {
|
||||
case 104: // h
|
||||
if (x == 0 && y == 0) {
|
||||
x = 7;
|
||||
y = 7;
|
||||
x_direction = 7;
|
||||
y_direction = 7;
|
||||
}
|
||||
if (x > 0) {
|
||||
for (x--; x > 0; x--) {
|
||||
x_direction--;
|
||||
@ -144,6 +175,7 @@ void controls() {
|
||||
}
|
||||
}
|
||||
else if (x == 0) {
|
||||
y--;
|
||||
x = 7;
|
||||
x_direction = 7;
|
||||
tile_selection();
|
||||
@ -156,6 +188,7 @@ void controls() {
|
||||
}
|
||||
}
|
||||
if (x == 0 && piece_color_to_int(board[y][x]) == 3) {
|
||||
y--;
|
||||
x = 7;
|
||||
x_direction = 7;
|
||||
tile_selection();
|
||||
@ -169,6 +202,12 @@ void controls() {
|
||||
}
|
||||
break;
|
||||
case 106: // j
|
||||
if (x == 0 && y == 7) {
|
||||
x = 7;
|
||||
y = 0;
|
||||
x_direction = 7;
|
||||
y_direction = -7;
|
||||
}
|
||||
if (y < 7) {
|
||||
for (y++; y < 7; y++) {
|
||||
y_direction++;
|
||||
@ -178,6 +217,7 @@ void controls() {
|
||||
}
|
||||
}
|
||||
else if (y == 7) {
|
||||
x--;
|
||||
y = 0;
|
||||
y_direction = -7;
|
||||
tile_selection();
|
||||
@ -190,6 +230,7 @@ void controls() {
|
||||
}
|
||||
}
|
||||
if (y == 7 && piece_color_to_int(board[y][x]) == 3) {
|
||||
x--;
|
||||
y = 0;
|
||||
y_direction = -7;
|
||||
tile_selection();
|
||||
@ -203,6 +244,12 @@ void controls() {
|
||||
}
|
||||
break;
|
||||
case 107: // k
|
||||
if (x == 0 && y == 0) {
|
||||
x = 7;
|
||||
y = 7;
|
||||
x_direction = 7;
|
||||
y_direction = 7;
|
||||
}
|
||||
if (y > 0) {
|
||||
for (y--; y > 0; y--) {
|
||||
y_direction--;
|
||||
@ -211,7 +258,8 @@ void controls() {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (y == 0) {
|
||||
else if (y == 0) {
|
||||
x
|
||||
y = 7;
|
||||
y_direction = 7;
|
||||
tile_selection();
|
||||
@ -270,14 +318,11 @@ void controls() {
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 13: // enter
|
||||
case 10: // enter
|
||||
a();
|
||||
break;
|
||||
case 113: // q
|
||||
printf("\x1b[?25h");
|
||||
exit(0);
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -296,24 +341,12 @@ int main() {
|
||||
printf("\x1b[H\x1b[J");
|
||||
printf("\x1b[?25l");
|
||||
|
||||
for (int y = 0; y < 8; ++y) {
|
||||
for (int x = 0; x < 8; ++x) {
|
||||
piece_color[y][x] = piece_color_to_int(board[y][x]);
|
||||
}
|
||||
}
|
||||
|
||||
print_tab();
|
||||
printf("\x1b[?1049h");
|
||||
|
||||
|
||||
//printf("\x1b[?47l");
|
||||
|
||||
//printf("\x1b[0;0Haaaa");
|
||||
|
||||
controls();
|
||||
|
||||
|
||||
printf("\x1b[10;0H\x1b[0m\x1b[?25l");
|
||||
printf("\x1b[10;0H\x1b[0m\x1b[?25h");
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user