je crois que les contrôles sont finis
This commit is contained in:
parent
2b838ff44a
commit
2c71b39e12
135
main.c
135
main.c
@ -24,12 +24,6 @@ typedef enum {
|
|||||||
WHITE_KING
|
WHITE_KING
|
||||||
} Pieces;
|
} Pieces;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
WHITE,
|
|
||||||
BLACK
|
|
||||||
} States;
|
|
||||||
|
|
||||||
|
|
||||||
char* piece_to_str(const Pieces piece) {
|
char* piece_to_str(const Pieces piece) {
|
||||||
switch (piece) {
|
switch (piece) {
|
||||||
case EMPTY: return "\u2800\u2800";
|
case EMPTY: return "\u2800\u2800";
|
||||||
@ -113,23 +107,7 @@ void print_tab() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tile_selection() {
|
void tile_selection() {
|
||||||
|
print_tab();
|
||||||
if (y % 2 == 1) {
|
|
||||||
if (x % 2 == 0) {
|
|
||||||
printf(FG_DEFAULT_BG_WHITE"\x1b[%d;%dH%s", y - y_direction + 1 , (x - x_direction) * 2 + 1, piece_to_str(board[y - y_direction][x - x_direction]));
|
|
||||||
}
|
|
||||||
if (x % 2 == 1) {
|
|
||||||
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]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (y % 2 == 0) {
|
|
||||||
if (x % 2 == 1) {
|
|
||||||
printf(FG_DEFAULT_BG_WHITE"\x1b[%d;%dH%s", y - y_direction + 1 , (x - x_direction) * 2 + 1, piece_to_str(board[y - y_direction][x-x_direction]));
|
|
||||||
}
|
|
||||||
if (x % 2 == 0) {
|
|
||||||
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;106m%s", y + 1 , x * 2 + 1, piece_to_str(board[y][x]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,16 +122,11 @@ void a() {
|
|||||||
printf("\x1b[%d;%dH\x1b[91;101m\u2800\u2800", y - 1 + 1 , x * 2 - 2 + 1);
|
printf("\x1b[%d;%dH\x1b[91;101m\u2800\u2800", y - 1 + 1 , x * 2 - 2 + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void controls() {
|
void controls() {
|
||||||
tile_selection();
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
tile_selection();
|
||||||
|
|
||||||
x_direction = 0;
|
x_direction = 0;
|
||||||
y_direction = 0;
|
y_direction = 0;
|
||||||
@ -163,103 +136,139 @@ void controls() {
|
|||||||
switch (input) {
|
switch (input) {
|
||||||
case 104: // h
|
case 104: // h
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
for (int i = x; i > 0; --i) {
|
for (x--; x > 0; x--) {
|
||||||
x--;
|
|
||||||
x_direction--;
|
x_direction--;
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (x == 0) {
|
||||||
x = 7;
|
x = 7;
|
||||||
x_direction = 7;
|
x_direction = 7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
x_direction = 0;
|
x_direction = 0;
|
||||||
for (int i = x; i > 0; --i) {
|
for (; x > 0; x--) {
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
x--;
|
|
||||||
x_direction--;
|
x_direction--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (x == 0 && piece_color_to_int(board[y][x]) == 3) {
|
||||||
|
x = 7;
|
||||||
|
x_direction = 7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
|
x_direction = 0;
|
||||||
|
for (; x > 0; x--) {
|
||||||
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x_direction--;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 106: // j
|
case 106: // j
|
||||||
if (y < 7) {
|
if (y < 7) {
|
||||||
for (int i = y; i < 7; ++i) {
|
for (y++; y < 7; y++) {
|
||||||
y++;
|
|
||||||
y_direction++;
|
y_direction++;
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (y == 7) {
|
||||||
y = 0;
|
y = 0;
|
||||||
y_direction = -7;
|
y_direction = -7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
y_direction = 0;
|
y_direction = 0;
|
||||||
for (int i = y; i < 7; ++i) {
|
for (; y < 7; y++) {
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y++;
|
|
||||||
y_direction++;
|
y_direction++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (y == 7 && piece_color_to_int(board[y][x]) == 3) {
|
||||||
|
y = 0;
|
||||||
|
y_direction = -7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
|
y_direction = 0;
|
||||||
|
for (; y < 7; y++) {
|
||||||
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y_direction++;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 107: // k
|
case 107: // k
|
||||||
if (y > 0) {
|
if (y > 0) {
|
||||||
for (int i = y; i > 0; --i) {
|
for (y--; y > 0; y--) {
|
||||||
y--;
|
|
||||||
y_direction--;
|
y_direction--;
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (y == 0) {
|
||||||
y = 7;
|
y = 7;
|
||||||
y_direction = 7;
|
y_direction = 7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
y_direction = 0;
|
y_direction = 0;
|
||||||
for (int i = y; i > 0; --i) {
|
for (; y > 0; y--) {
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
y--;
|
|
||||||
y_direction--;
|
y_direction--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (y == 0 && piece_color_to_int(board[y][x]) == 3) {
|
||||||
|
y = 7;
|
||||||
|
y_direction = 7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
|
y_direction = 0;
|
||||||
|
for (; y > 0; y--) {
|
||||||
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y_direction--;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 108: // l
|
case 108: // l
|
||||||
if (x < 7) {
|
if (x < 7) {
|
||||||
for (int i = x; i < 7; ++i) {
|
for (x++; x < 7; x++) {
|
||||||
x++;
|
|
||||||
x_direction++;
|
x_direction++;
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (x == 7) {
|
||||||
x = 0;
|
x = 0;
|
||||||
x_direction = -7;
|
x_direction = -7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
x_direction = 0;
|
x_direction = 0;
|
||||||
for (int i = x; i < 7; ++i) {
|
for (; x < 7; x++) {
|
||||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
x++;
|
|
||||||
x_direction++;
|
x_direction++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (x == 7 && piece_color_to_int(board[y][x]) == 3) {
|
||||||
|
x = 0;
|
||||||
|
x_direction = -7;
|
||||||
tile_selection();
|
tile_selection();
|
||||||
|
x_direction = 0;
|
||||||
|
for (; x < 7; x++) {
|
||||||
|
if (piece_color_to_int(board[y][x]) == 1 || piece_color_to_int(board[y][x]) == 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x_direction++;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@ -271,7 +280,6 @@ void controls() {
|
|||||||
exit(0);
|
exit(0);
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,13 +302,18 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_tab(board);
|
print_tab();
|
||||||
|
printf("\x1b[?1049h");
|
||||||
|
|
||||||
|
|
||||||
|
//printf("\x1b[?47l");
|
||||||
|
|
||||||
|
//printf("\x1b[0;0Haaaa");
|
||||||
|
|
||||||
controls();
|
controls();
|
||||||
|
|
||||||
|
|
||||||
printf("\x1b[0m");
|
printf("\x1b[10;0H\x1b[0m\x1b[?25l");
|
||||||
printf("\x1b[10;0H");
|
|
||||||
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