correction du bug de couleur du bg quand on change de piece
This commit is contained in:
parent
996fa89a7c
commit
2b838ff44a
134
main.c
134
main.c
@ -69,16 +69,15 @@ int piece_color_to_int(Pieces piece) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pieces board[8][8] = {
|
Pieces board[8][8] = {
|
||||||
{BLACK_ROOK, BLACK_KNIGHT, BLACK_BISHOP, BLACK_QUEEN, BLACK_KING, BLACK_BISHOP, BLACK_KNIGHT, BLACK_ROOK},
|
{BLACK_ROOK, EMPTY, BLACK_BISHOP, EMPTY, EMPTY, BLACK_ROOK, BLACK_KING, EMPTY},
|
||||||
{BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN},
|
{BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, EMPTY, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN},
|
||||||
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
|
{EMPTY, BLACK_KNIGHT, EMPTY, BLACK_PAWN, EMPTY, EMPTY, EMPTY, EMPTY},
|
||||||
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
|
{EMPTY, EMPTY, EMPTY, EMPTY, WHITE_PAWN, BLACK_KNIGHT, EMPTY, EMPTY},
|
||||||
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
|
{EMPTY, EMPTY, WHITE_BISHOP, WHITE_PAWN, EMPTY, EMPTY, EMPTY, EMPTY},
|
||||||
{EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY},
|
{EMPTY, EMPTY, WHITE_KNIGHT, EMPTY, EMPTY, WHITE_KNIGHT, EMPTY, EMPTY},
|
||||||
{WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN},
|
{WHITE_PAWN, WHITE_PAWN, WHITE_PAWN, EMPTY, EMPTY, WHITE_PAWN, WHITE_PAWN, WHITE_PAWN},
|
||||||
{WHITE_ROOK, WHITE_KNIGHT, WHITE_BISHOP, WHITE_QUEEN, WHITE_KING, WHITE_BISHOP, WHITE_KNIGHT, WHITE_ROOK}
|
{WHITE_ROOK, EMPTY, EMPTY, WHITE_QUEEN, EMPTY, WHITE_ROOK, WHITE_KING, EMPTY}
|
||||||
};
|
};
|
||||||
|
|
||||||
int piece_color[8][8];
|
int piece_color[8][8];
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 7;
|
int y = 7;
|
||||||
@ -88,7 +87,7 @@ bool player_track = true;
|
|||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
int print_tab() {
|
void print_tab() {
|
||||||
for (int y = 0; y < 8; ++y) {
|
for (int y = 0; y < 8; ++y) {
|
||||||
for (int x = 0; x < 8; ++x) {
|
for (int x = 0; x < 8; ++x) {
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
@ -108,9 +107,9 @@ int print_tab() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf("\x1b[39;49m");
|
printf("\x1b[0m");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tile_selection() {
|
void tile_selection() {
|
||||||
@ -163,10 +162,71 @@ void controls() {
|
|||||||
|
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 104: // h
|
case 104: // h
|
||||||
|
if (x > 0) {
|
||||||
|
for (int i = x; i > 0; --i) {
|
||||||
|
x--;
|
||||||
|
x_direction--;
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x = 7;
|
||||||
|
x_direction = 7;
|
||||||
|
tile_selection();
|
||||||
|
x_direction = 0;
|
||||||
|
for (int i = x; i > 0; --i) {
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x--;
|
||||||
|
x_direction--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tile_selection();
|
||||||
|
break;
|
||||||
case 106: // j
|
case 106: // j
|
||||||
|
if (y < 7) {
|
||||||
|
for (int i = y; i < 7; ++i) {
|
||||||
|
y++;
|
||||||
|
y_direction++;
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
y = 0;
|
||||||
|
y_direction = -7;
|
||||||
|
tile_selection();
|
||||||
|
y_direction = 0;
|
||||||
|
for (int i = y; i < 7; ++i) {
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
y_direction++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tile_selection();
|
||||||
|
break;
|
||||||
case 107: // k
|
case 107: // k
|
||||||
if (y >= 0) {
|
if (y > 0) {
|
||||||
for (int i = y; i < 8; ++i) {
|
for (int i = y; i > 0; --i) {
|
||||||
|
y--;
|
||||||
|
y_direction--;
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
y = 7;
|
||||||
|
y_direction = 7;
|
||||||
|
tile_selection();
|
||||||
|
y_direction = 0;
|
||||||
|
for (int i = y; i > 0; --i) {
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -174,12 +234,33 @@ void controls() {
|
|||||||
y_direction--;
|
y_direction--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tile_selection();
|
||||||
|
break;
|
||||||
|
case 108: // l
|
||||||
|
if (x < 7) {
|
||||||
|
for (int i = x; i < 7; ++i) {
|
||||||
|
x++;
|
||||||
|
x_direction++;
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
y = 7;
|
x = 0;
|
||||||
y_direction = 1;
|
x_direction = -7;
|
||||||
|
tile_selection();
|
||||||
|
x_direction = 0;
|
||||||
|
for (int i = x; i < 7; ++i) {
|
||||||
|
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
x_direction++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tile_selection();
|
tile_selection();
|
||||||
case 108: // l
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 13: // enter
|
case 13: // enter
|
||||||
@ -190,16 +271,21 @@ void controls() {
|
|||||||
exit(0);
|
exit(0);
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const struct termios old_termios;
|
struct termios t_old, t_new;
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_termios);
|
|
||||||
|
tcgetattr(STDIN_FILENO, &t_old);
|
||||||
|
t_new = t_old;
|
||||||
|
t_new.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_new);
|
||||||
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
setlocale(LC_ALL, "en_US.UTF-8");
|
setlocale(LC_ALL, "en_US.UTF-8");
|
||||||
printf("\n");
|
printf("\x1b[H\x1b[J");
|
||||||
printf("\x1b[H");
|
|
||||||
printf("\x1b[?25l");
|
printf("\x1b[?25l");
|
||||||
|
|
||||||
for (int y = 0; y < 8; ++y) {
|
for (int y = 0; y < 8; ++y) {
|
||||||
@ -213,11 +299,9 @@ int main() {
|
|||||||
controls();
|
controls();
|
||||||
|
|
||||||
|
|
||||||
|
printf("\x1b[0m");
|
||||||
|
|
||||||
|
|
||||||
getchar();
|
|
||||||
printf("\x1b[10;0H");
|
printf("\x1b[10;0H");
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user