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