Commit | Line | Data |
---|---|---|
7515f897 JB |
1 | /* |
2 | * ===================================================================================== | |
3 | * | |
4 | * Filename: display.c | |
5 | * | |
6 | * Description: Routines to handle the display | |
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 | ||
26 | void print_board(int y, int x) { | |
811d4abe | 27 | |
7515f897 JB |
28 | mvprintw(y, x, " | |"); |
29 | mvprintw(y+1, x, " | |"); | |
30 | mvprintw(y+2, x, "----+----+----"); | |
31 | mvprintw(y+3, x, " | |"); | |
32 | mvprintw(y+4, x, " | |"); | |
33 | mvprintw(y+5, x, "----+----+----"); | |
34 | mvprintw(y+6, x, " | |"); | |
35 | mvprintw(y+7, x, " | |"); | |
36 | } | |
37 | ||
38 | /* there's only nine valid (y, x) 2-uplets for this two shapes | |
39 | * that are : - base_y, base_x +1 | |
40 | * - base_y, base_x + 6 | |
41 | * - base_y, base_x + 11 | |
42 | * - base_y + 3, base_x + 1 | |
43 | * - base_y + 6, base_x + 1 | |
44 | * - base_y + 3, base_x + 6 | |
45 | * - base_y + 3, base_x + 11 | |
46 | * - base_y + 6, base_x + 6 | |
47 | * - base_y + 6, base_x + 11 | |
5df3071e JB |
48 | * The added (y, x) couple values can be {0, 3, 6}x{1, 6, 11} |
49 | */ | |
7515f897 | 50 | |
811d4abe JB |
51 | static void print_x(int y, int x) { |
52 | ||
7515f897 JB |
53 | mvprintw(y, x, "\\/"); |
54 | mvprintw(y+1, x,"/\\"); | |
55 | } | |
56 | ||
811d4abe JB |
57 | static void print_o(int y, int x) { |
58 | ||
7515f897 JB |
59 | mvprintw(y, x, "/\\"); |
60 | mvprintw(y+1, x, "\\/"); | |
61 | } | |
5df3071e JB |
62 | |
63 | /* y: 1 -> +0 x: 1 -> +1 | |
64 | * 2 -> +3 2 -> +6 | |
65 | * 3 -> +6 3 -> +11 */ | |
66 | static int remap_y(int y) { | |
811d4abe | 67 | |
5df3071e JB |
68 | if (y == 1) { |
69 | return 0; | |
70 | } else if (y == 2) { | |
71 | return 3; | |
72 | } else { | |
73 | return 6; | |
74 | } | |
75 | } | |
76 | ||
77 | static int remap_x(int x) { | |
811d4abe | 78 | |
5df3071e JB |
79 | if (x == 1) { |
80 | return 1; | |
81 | } else if (x == 2) { | |
82 | return 6; | |
83 | } else { | |
84 | return 11; | |
85 | } | |
86 | } | |
87 | ||
88 | void print_coordinates(coordinates_t coordinates_array[], int base_y, int base_x) { | |
89 | unsigned i = 0; | |
811d4abe | 90 | |
5df3071e JB |
91 | while ((coordinates_array + i)->y != 0 && (coordinates_array + i)->x != 0) { |
92 | if ((coordinates_array + i)->type == 0) { | |
93 | print_o(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); | |
94 | } else { | |
95 | print_x(base_y + remap_y((coordinates_array + i)->y), base_x + remap_x((coordinates_array + i)->x)); | |
96 | } | |
97 | i++; | |
98 | } | |
99 | } | |
811d4abe JB |
100 | |
101 | /* void printf_result(unsigned player, unsigned round) { | |
102 | char* result_msg = ""; | |
103 | ||
104 | if (round < MAX_COORDINATES + 1) { | |
105 | if (player == 0) { | |
106 | result_msg = "Joueur 1"; | |
107 | } else { | |
108 | result_msg = "Joueur 2"; | |
109 | } | |
110 | printf("%s gagne !\n", result_msg); | |
111 | } else { | |
112 | printf("Egalite !\n"); | |
113 | } | |
114 | } */ | |
115 |