// Code ci-dessous à copier/coller au début du fichier courses_nom_prenom.c #include struct Point { int x; int y; }; typedef struct Point Point; struct Vector { int x; int y; }; typedef struct Vector Vector; Point* new_Point(int x, int y){ Point* pt = malloc(sizeof(Point)); pt->x = x; pt->y = y; return pt; } Vector* new_Vector(int x, int y){ Vector * v = malloc(sizeof(Vector)); v->x = x; v->y = y; return v; } bool equals_Point(Point* a, Point* b){ return a->x == b->x && a->y == b->y; } void print_colored(char* str, char* fore, char* back){ printf("%s", fore); printf("%s", back); printf("%s", str); printf("\x1b[0m"); } void draw(Vector* size, Point* car_pos, Point* first, Point* second){ char* car = "O"; char* empty = "_"; /* * https://en.wikipedia.org/wiki/ANSI_escape_code#Colors * \x1b = escape char code for C * [(number)m; control code * * Examples: * \x1b[1m; = bold text * \x1b[35m; = magenta colored text */ char* car_fore = "\x1b[31m"; char* car_back = "\x1b[41m"; char* first_fore = "\x1b[32m"; char* first_back = "\x1b[42m"; char* second_fore = "\x1b[33m"; char* second_back = "\x1b[43m"; char* empty_fore = "\x1b[95m"; char* empty_back = "\x1b[105m"; Point* index = new_Point(0, 0); //no need to free it, its memory address is constant for(; index->y < size->y; index->y++){ printf("%s", "|"); for(index->x = 0 ; index->x < size->x; index->x++){ if(equals_Point(index, car_pos)){ print_colored(car, car_fore, car_back); } else if (equals_Point(index, first)){ print_colored(car, first_fore, first_back); } else if (equals_Point(index, second)){ print_colored(car, second_fore, second_back); } else{ print_colored(empty, empty_fore, empty_back); } printf("%s", "|"); } printf("%s", "\n"); } } // Code ci-dessus à copier/coller au début du fichier courses_nom_prenom.c /* =========================================================================*/ // Code ci-dessous à copier/coller dans le while de la fonction main() system("clear"); // Pour Linux /* system("cls"); // Pour Windows */ Vector* size = new_Vector(TAILLEPLATEAU, TAILLEPLATEAU); Point* car_pos = new_Point(pos_x, pos_y); Point* first = new_Point(portes[obj_courant][0], portes[obj_courant][1]); Point* second = new_Point(portes[obj_next][0], portes[obj_next][1]); draw(size, car_pos, first, second);