je dois partir
This commit is contained in:
parent
d07587c654
commit
996fa89a7c
80
main.c
80
main.c
@ -3,6 +3,7 @@
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FG_DEFAULT_BG_WHITE "\x1b[30;48;5;255m"
|
||||
#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) {
|
||||
case EMPTY: return 3;
|
||||
case BLACK_PAWN:
|
||||
@ -83,7 +84,7 @@ int x = 0;
|
||||
int y = 7;
|
||||
int x_direction = 0;
|
||||
int y_direction = 0;
|
||||
|
||||
bool player_track = true;
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
@ -112,7 +113,7 @@ int print_tab() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void piece_selection() {
|
||||
void tile_selection() {
|
||||
|
||||
if (y % 2 == 1) {
|
||||
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]));
|
||||
}
|
||||
|
||||
void controls() {
|
||||
piece_selection();
|
||||
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 (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) {
|
||||
|
||||
x_direction = 0;
|
||||
@ -146,54 +163,29 @@ void controls() {
|
||||
|
||||
switch (input) {
|
||||
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
|
||||
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
|
||||
if (y > 6 && (piece_color[y - 1][x] == 1 || piece_color[y - 1][x] == 2)) {
|
||||
if (y >= 0) {
|
||||
for (int i = y; i < 8; ++i) {
|
||||
if (piece_color[y][x] == 1 || piece_color[y][x] == 2) {
|
||||
break;
|
||||
}
|
||||
y--;
|
||||
y_direction = -1;
|
||||
piece_selection();
|
||||
y_direction--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
y = 7;
|
||||
y_direction = 1;
|
||||
piece_selection();
|
||||
}
|
||||
break;
|
||||
tile_selection();
|
||||
case 108: // l
|
||||
if (x < 7 && (piece_color[y][x + 1] == 1 || piece_color[y][x + 1] == 2)) {
|
||||
x++;
|
||||
x_direction++;
|
||||
piece_selection();
|
||||
}
|
||||
else {
|
||||
x = 0;
|
||||
x_direction = -7;
|
||||
piece_selection();
|
||||
}
|
||||
|
||||
|
||||
case 13: // enter
|
||||
a();
|
||||
break;
|
||||
case 113:
|
||||
case 113: // q
|
||||
printf("\x1b[?25h");
|
||||
exit(0);
|
||||
default: break;
|
||||
@ -212,7 +204,7 @@ int main() {
|
||||
|
||||
for (int y = 0; y < 8; ++y) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user