support des controles pour h j k l
This commit is contained in:
parent
c7d04ddb25
commit
e49f038573
73
main.c
73
main.c
@ -1,4 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define FG_WHITE_BG_WHITE "\x1b[38;5;255;48;5;255m"
|
||||
#define FG_136_BG_136 "\x1b[38;5;136;48;5;136m"
|
||||
@ -21,6 +27,11 @@ typedef enum {
|
||||
WHITE_KING
|
||||
} Pieces;
|
||||
|
||||
typedef enum {
|
||||
WHITE,
|
||||
BLACK
|
||||
} States;
|
||||
|
||||
char* piece_to_str(const Pieces piece) {
|
||||
switch (piece) {
|
||||
case EMPTY: return "\u2800\u2800";
|
||||
@ -40,6 +51,28 @@ char* piece_to_str(const Pieces piece) {
|
||||
}
|
||||
}
|
||||
|
||||
int piece_color_to_str(Pieces piece) {
|
||||
switch (piece) {
|
||||
case EMPTY: return 3;
|
||||
case BLACK_PAWN:
|
||||
case BLACK_ROOK:
|
||||
case BLACK_KNIGHT:
|
||||
case BLACK_BISHOP:
|
||||
case BLACK_QUEEN:
|
||||
case BLACK_KING: return 2;
|
||||
case WHITE_PAWN:
|
||||
case WHITE_ROOK:
|
||||
case WHITE_KNIGHT:
|
||||
case WHITE_BISHOP:
|
||||
case WHITE_QUEEN:
|
||||
case WHITE_KING: return 1;
|
||||
default: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
int piece_color[8][8];
|
||||
|
||||
|
||||
|
||||
int print_tab(Pieces board[8][8]) {
|
||||
for (int y = 0; y < 8; ++y) {
|
||||
@ -62,12 +95,39 @@ int print_tab(Pieces board[8][8]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\x1b[39;49m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int a() {}
|
||||
int a() {
|
||||
int x = 0;
|
||||
int y = 7;
|
||||
|
||||
int input = getchar();
|
||||
|
||||
switch (input) {
|
||||
case 104: // h
|
||||
case 106: // j
|
||||
case 107: // k
|
||||
case 108: // l
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
const struct termios old_termios;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_termios);
|
||||
|
||||
setlocale(LC_ALL, "en_US.UTF-8");
|
||||
printf("\n");
|
||||
printf("\x1b[H");
|
||||
printf("\x1b[2J");
|
||||
|
||||
Pieces board[8][8] = {
|
||||
{BLACK_ROOK, BLACK_KNIGHT, BLACK_BISHOP, BLACK_QUEEN, BLACK_KING, BLACK_BISHOP, BLACK_KNIGHT, BLACK_ROOK},
|
||||
{BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN, BLACK_PAWN},
|
||||
@ -79,11 +139,18 @@ int main() {
|
||||
{WHITE_ROOK, WHITE_KNIGHT, WHITE_BISHOP, WHITE_QUEEN, WHITE_KING, WHITE_BISHOP, WHITE_KNIGHT, WHITE_ROOK}
|
||||
};
|
||||
|
||||
printf("\x1b[2J"); // Clear du terminal
|
||||
printf("\x1b[H"); // Déplacement du curseur au (0, 0)
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
print_tab(board);
|
||||
|
||||
a();
|
||||
|
||||
|
||||
getchar();
|
||||
printf("\x1b[10;0H"); // Déplacement du curseur juste en dessous du tableau de jeu
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user