#include <stdio.h>
#include <termios.h>
#include <unistd.h>
static void mode_raw(int);
static void terrain(void);
static void deplacement(void);
int main(void) {
terrain();
deplacement();
}
void deplacement(void) {
unsigned char c;
int x=2,y=2;
mode_raw(1);
terrain();
printf("\x1B[%.2d;%.2dH",y,x);
c = getchar();
while(c!='q') {
if(c == 10) {printf("*");}
if(c == 32) {printf("#");}
if(c == 27) {c = getchar();}
if(c == 91) {c = getchar();}
if(c == 65) {y=y-2;}
if(c == 68) {x=x-2;}
if(c == 66) {y=y+2;}
if(c == 67) {x=x+2;}
printf("\x1B[%.2d;%.2dH",y,x);
}
mode_raw(0);
}
void terrain(void) {
printf("\x1B[2J\x1B[;H");
printf("\x1B[%.2d;%.2dH",1,1); printf("+-+-+-+-+-+-+-+-+-+-+\n");
printf("\x1B[%.2d;%.2dH",2,1); printf("| | | | | | | | | | |\n");
printf("\x1B[%.2d;%.2dH",3,1); printf("+-+-+-+-+-+-+-+-+-+-+\n");
printf("\x1B[%.2d;%.2dH",4,1); printf("| | | | | | | | | | |\n");
printf("\x1B[%.2d;%.2dH",5,1); printf("+-+-+-+-+-+-+-+-+-+-+\n");
printf("\x1B[%.2d;%.2dH",6,1); printf("| | | | | | | | | | |\n");
printf("\x1B[%.2d;%.2dH",7,1); printf("+-+-+-+-+-+-+-+-+-+-+\n");
printf("\x1B[%.2d;%.2dH",8,1); printf("| | | | | | | | | | |\n");
printf("\x1B[%.2d;%.2dH",9,1); printf("+-+-+-+-+-+-+-+-+-+-+\n");
printf("\x1B[%.2d;%.2dH",10,1);printf("| | | | | | | | | | |\n");
printf("\x1B[%.2d;%.2dH",11,1);printf("+-+-+-+-+-+-+-+-+-+-+\n");
}
void mode_raw(int activer) {
static struct termios cooked;
static int raw_actif = 0;
if (raw_actif == activer) {return;}
if (activer) {
struct termios raw;
tcgetattr(STDIN_FILENO, &cooked);
raw = cooked;
cfmakeraw(&raw);
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
}
else
{tcsetattr(STDIN_FILENO, TCSANOW, &cooked);}
raw_actif = activer;
}
Partager