Commit | Line | Data |
---|---|---|
480acfeb JB |
1 | /* |
2 | * ===================================================================================== | |
3 | * | |
4 | * Filename: ui.c | |
5 | * | |
6 | * Description: Routines to handle the user interface | |
7 | * | |
8 | * Version: 1.0 | |
9 | * Created: 24/04/2017 16:41:15 | |
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 | ||
21 | #include "ui.h" | |
22 | ||
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 | ||
26 | /* FIXME: one can split this shape in building blocks and build it using them */ | |
27 | void print_board(int y, int x) { | |
28 | ||
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 | ||
39 | static void print_x(int y, int x) { | |
40 | ||
41 | mvprintw(y, x, "\\/"); | |
42 | mvprintw(y+1, x,"/\\"); | |
43 | } | |
44 | ||
45 | static void print_o(int y, int x) { | |
46 | ||
47 | mvprintw(y, x, "/\\"); | |
48 | mvprintw(y+1, x, "\\/"); | |
49 | } | |
50 | ||
51 | /* y: 1 -> +0 x: 1 -> +1 | |
52 | * 2 -> +3 2 -> +6 | |
53 | * 3 -> +6 3 -> +11 */ | |
54 | static int remap_y(int y) { | |
55 | ||
56 | if (y == 1) { | |
57 | return 0; | |
58 | } else if (y == 2) { | |
59 | return 3; | |
60 | } else { | |
61 | return 6; | |
62 | } | |
63 | } | |
64 | ||
65 | static int remap_x(int x) { | |
66 | ||
67 | if (x == 1) { | |
68 | return 1; | |
69 | } else if (x == 2) { | |
70 | return 6; | |
71 | } else { | |
72 | return 11; | |
73 | } | |
74 | } |