Commit | Line | Data |
---|---|---|
7515f897 JB |
1 | /* |
2 | * ===================================================================================== | |
3 | * | |
4 | * Filename: display.c | |
5 | * | |
fe6636a2 | 6 | * Description: Routines to handle the display |
7515f897 JB |
7 | * |
8 | * Version: 1.0 | |
9 | * Created: 15/03/2017 20:06:11 | |
10 | * Revision: none | |
11 | * Compiler: gcc | |
12 | * | |
13 | * Author: Jerome Benoit (fraggle), jerome.benoit@piment-noir.org | |
14 | * Organization: Piment Noir | |
15 | * | |
16 | * ===================================================================================== | |
17 | */ | |
18 | ||
19 | #include <ncurses.h> | |
20 | ||
5df3071e JB |
21 | #include "display.h" |
22 | ||
7515f897 JB |
23 | /* in all print routine, y and x are the coordinates of the first character of the shape |
24 | * which can be a space ' ' */ | |
25 | ||
8f8629b2 | 26 | /* FIXME: one can split this shape in building blocks and build it using them */ |
7515f897 | 27 | void print_board(int y, int x) { |
811d4abe | 28 | |
7515f897 JB |
29 | mvprintw(y, x, " | |"); |
30 | mvprintw(y+1, x, " | |"); | |
31 | mvprintw(y+2, x, "----+----+----"); | |
32 | mvprintw(y+3, x, " | |"); | |
33 | mvprintw(y+4, x, " | |"); | |
34 | mvprintw(y+5, x, "----+----+----"); | |
35 | mvprintw(y+6, x, " | |"); | |
36 | mvprintw(y+7, x, " | |"); | |
37 | } | |
38 | ||
fe6636a2 | 39 | /* there's only nine valid (y, x) 2-uplets for this two shapes |
7515f897 JB |
40 | * that are : - base_y, base_x +1 |
41 | * - base_y, base_x + 6 | |
fe6636a2 JB |
42 | * - base_y, base_x + 11 |
43 | * - base_y + 3, base_x + 1 | |
44 | * - base_y + 6, base_x + 1 | |
45 | * - base_y + 3, base_x + 6 | |
46 | * - base_y + 3, base_x + 11 | |
47 | * - base_y + 6, base_x + 6 | |
48 | * - base_y + 6, base_x + 11 | |
5df3071e JB |
49 | * The added (y, x) couple values can be {0, 3, 6}x{1, 6, 11} |
50 | */ | |
7515f897 | 51 | |
811d4abe JB |
52 | static void print_x(int y, int x) { |
53 | ||
7515f897 JB |
54 | mvprintw(y, x, "\\/"); |
55 | mvprintw(y+1, x,"/\\"); | |
56 | } | |
57 | ||
811d4abe JB |
58 | static void print_o(int y, int x) { |
59 | ||
7515f897 JB |
60 | mvprintw(y, x, "/\\"); |
61 | mvprintw(y+1, x, "\\/"); | |
62 | } | |
5df3071e JB |
63 | |
64 | /* y: 1 -> +0 x: 1 -> +1 | |
65 | * 2 -> +3 2 -> +6 | |
66 | * 3 -> +6 3 -> +11 */ | |
67 | static int remap_y(int y) { | |
811d4abe | 68 | |
5df3071e JB |
69 | if (y == 1) { |
70 | return 0; | |
98edfbe1 JB |
71 | } else if (y > 1 && y <= 3) { |
72 | return (remap_y(y - 1) + 3); | |
73 | } else { | |
995c32c8 | 74 | return -1; |
5df3071e JB |
75 | } |
76 | } | |
77 | ||
78 | static int remap_x(int x) { | |
811d4abe | 79 | |
5df3071e JB |
80 | if (x == 1) { |
81 | return 1; | |
98edfbe1 JB |
82 | } else if (x > 1 && x <= 3) { |
83 | return (remap_x(x - 1) + 5); | |
5df3071e | 84 | } else { |
995c32c8 | 85 | return -1; |
5df3071e JB |
86 | } |
87 | } | |
88 | ||
89 | void print_coordinates(coordinates_t coordinates_array[], int base_y, int base_x) { | |
90 | unsigned i = 0; | |
811d4abe | 91 | |
995c32c8 JB |
92 | while ((coordinates_array + i)->y != 0 && (coordinates_array + i)->x != 0 && \ |
93 | i < MAX_COORDINATES) { | |
5df3071e JB |
94 | if ((coordinates_array + i)->type == 0) { |
95 | print_o(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); | |
96 | } else { | |
97 | print_x(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); | |
98 | } | |
99 | i++; | |
100 | } | |
101 | } |