X-Git-Url: https://git.piment-noir.org/?p=TD_C.git;a=blobdiff_plain;f=TP_13%2Fexo2%2Flib%2Fdisplay.c;h=1e5def8f66dc154056b67e1e4defcc6661ee732a;hp=22deb96a41a7e7a06ede4fb8462c2d98fecea892;hb=5df3071eec60ca43bc66e1266820de0572d4b629;hpb=aae22ca298198e5791490702bfceefd78a0140b2 diff --git a/TP_13/exo2/lib/display.c b/TP_13/exo2/lib/display.c index 22deb96..1e5def8 100644 --- a/TP_13/exo2/lib/display.c +++ b/TP_13/exo2/lib/display.c @@ -18,6 +18,8 @@ #include +#include "display.h" + /* in all print routine, y and x are the coordinates of the first character of the shape * which can be a space ' ' */ @@ -42,8 +44,8 @@ void print_board(int y, int x) { * - base_y + 3, base_x + 11 * - base_y + 6, base_x + 6 * - base_y + 6, base_x + 11 - * The added y value can be {0, 3, 6} - * The added x value can be {1, 6, 11} */ + * The added (y, x) couple values can be {0, 3, 6}x{1, 6, 11} + */ void print_x(int y, int x) { mvprintw(y, x, "\\/"); @@ -54,3 +56,38 @@ void print_o(int y, int x) { mvprintw(y, x, "/\\"); mvprintw(y+1, x, "\\/"); } + +/* y: 1 -> +0 x: 1 -> +1 + * 2 -> +3 2 -> +6 + * 3 -> +6 3 -> +11 */ +static int remap_y(int y) { + if (y == 1) { + return 0; + } else if (y == 2) { + return 3; + } else { + return 6; + } +} + +static int remap_x(int x) { + if (x == 1) { + return 1; + } else if (x == 2) { + return 6; + } else { + return 11; + } +} + +void print_coordinates(coordinates_t coordinates_array[], int base_y, int base_x) { + unsigned i = 0; + while ((coordinates_array + i)->y != 0 && (coordinates_array + i)->x != 0) { + if ((coordinates_array + i)->type == 0) { + print_o(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); + } else { + print_x(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); + } + i++; + } +}