X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_13%2Fexo2%2Flib%2Fdisplay.c;h=34343a05e215d7f91bf72025bd96799cfd7b778f;hb=fe6636a2e2488427b01931aa6a40d7105f9b3dd2;hp=21d85bb84cbece58dff339b217de62212d6cfb3a;hpb=811d4abe716c4d14629cee5beda1e1f3cff979bc;p=TD_C.git diff --git a/TP_13/exo2/lib/display.c b/TP_13/exo2/lib/display.c index 21d85bb..34343a0 100644 --- a/TP_13/exo2/lib/display.c +++ b/TP_13/exo2/lib/display.c @@ -3,7 +3,7 @@ * * Filename: display.c * - * Description: Routines to handle the display + * Description: Routines to handle the display * * Version: 1.0 * Created: 15/03/2017 20:06:11 @@ -23,6 +23,7 @@ /* in all print routine, y and x are the coordinates of the first character of the shape * which can be a space ' ' */ +/* FIXME: one can split this shape in building blocks and build it using them */ void print_board(int y, int x) { mvprintw(y, x, " | |"); @@ -35,16 +36,16 @@ void print_board(int y, int x) { mvprintw(y+7, x, " | |"); } -/* there's only nine valid (y, x) 2-uplets for this two shapes +/* there's only nine valid (y, x) 2-uplets for this two shapes * that are : - base_y, base_x +1 * - base_y, base_x + 6 - * - base_y, base_x + 11 - * - base_y + 3, base_x + 1 - * - base_y + 6, base_x + 1 - * - base_y + 3, base_x + 6 - * - base_y + 3, base_x + 11 - * - base_y + 6, base_x + 6 - * - base_y + 6, base_x + 11 + * - base_y, base_x + 11 + * - base_y + 3, base_x + 1 + * - base_y + 6, base_x + 1 + * - base_y + 3, base_x + 6 + * - base_y + 3, base_x + 11 + * - base_y + 6, base_x + 6 + * - base_y + 6, base_x + 11 * The added (y, x) couple values can be {0, 3, 6}x{1, 6, 11} */ @@ -67,10 +68,10 @@ static int remap_y(int y) { if (y == 1) { return 0; - } else if (y == 2) { - return 3; - } else { - return 6; + } else if (y > 1 && y <= 3) { + return (remap_y(y - 1) + 3); + } else { + return -1; } } @@ -78,17 +79,18 @@ static int remap_x(int x) { if (x == 1) { return 1; - } else if (x == 2) { - return 6; + } else if (x > 1 && x <= 3) { + return (remap_x(x - 1) + 5); } else { - return 11; + return -1; } } 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) { + while ((coordinates_array + i)->y != 0 && (coordinates_array + i)->x != 0 && \ + i < MAX_COORDINATES) { 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 { @@ -97,19 +99,3 @@ void print_coordinates(coordinates_t coordinates_array[], int base_y, int base_x i++; } } - -/* void printf_result(unsigned player, unsigned round) { - char* result_msg = ""; - - if (round < MAX_COORDINATES + 1) { - if (player == 0) { - result_msg = "Joueur 1"; - } else { - result_msg = "Joueur 2"; - } - printf("%s gagne !\n", result_msg); - } else { - printf("Egalite !\n"); - } -} */ -