je dois partir

This commit is contained in:
alberr_b0yyy 2025-06-12 15:45:26 +02:00
parent d07587c654
commit 996fa89a7c

82
main.c
View File

@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include <locale.h> #include <locale.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.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"
@ -48,7 +49,7 @@ char* piece_to_str(const Pieces piece) {
} }
} }
int piece_color_to_str(Pieces piece) { int piece_color_to_int(Pieces piece) {
switch (piece) { switch (piece) {
case EMPTY: return 3; case EMPTY: return 3;
case BLACK_PAWN: case BLACK_PAWN:
@ -83,7 +84,7 @@ int x = 0;
int y = 7; int y = 7;
int x_direction = 0; int x_direction = 0;
int y_direction = 0; int y_direction = 0;
bool player_track = true;
////////////////////////////////////////// //////////////////////////////////////////
@ -112,7 +113,7 @@ int print_tab() {
return 0; return 0;
} }
void piece_selection() { void tile_selection() {
if (y % 2 == 1) { if (y % 2 == 1) {
if (x % 2 == 0) { if (x % 2 == 0) {
@ -133,10 +134,26 @@ void piece_selection() {
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]));
} }
void controls() { void a() {
piece_selection(); 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 (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);
}
}
}
void controls() {
tile_selection();
while (1) { while (1) {
x_direction = 0; x_direction = 0;
@ -146,54 +163,29 @@ void controls() {
switch (input) { switch (input) {
case 104: // h case 104: // h
if (x > 0 && (piece_color[y][x - 1] == 1 || piece_color[y][x - 1] == 2)) {
x--;
x_direction--;
piece_selection();
}
else {
x = 7;
x_direction = 7;
piece_selection();
}
break;
case 106: // j case 106: // j
if (y < 7 && (piece_color[y + 1][x] == 1 || piece_color[y + 1][x] == 2)) {
y++;
y_direction++;
piece_selection();
}
else {
y = 6;
y_direction--;
piece_selection();
}
break;
case 107: // k case 107: // k
if (y > 6 && (piece_color[y - 1][x] == 1 || piece_color[y - 1][x] == 2)) { if (y >= 0) {
y--; for (int i = y; i < 8; ++i) {
y_direction = -1; if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
piece_selection(); break;
}
y--;
y_direction--;
}
} }
else { else {
y = 7; y = 7;
y_direction = 1; y_direction = 1;
piece_selection();
} }
break; tile_selection();
case 108: // l case 108: // l
if (x < 7 && (piece_color[y][x + 1] == 1 || piece_color[y][x + 1] == 2)) {
x++;
x_direction++; case 13: // enter
piece_selection(); a();
}
else {
x = 0;
x_direction = -7;
piece_selection();
}
break; break;
case 113: case 113: // q
printf("\x1b[?25h"); printf("\x1b[?25h");
exit(0); exit(0);
default: break; default: break;
@ -212,7 +204,7 @@ int main() {
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) {
piece_color[y][x] = piece_color_to_str(board[y][x]); piece_color[y][x] = piece_color_to_int(board[y][x]);
} }
} }