1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <ncurses.h>
#include "pieces.h"
/*
* ncurses ui has an x scale factor of 2
*/
void printrect(int y, int x, int h, int w) {
// print rectangle whose left corner is at (y, x) and internal area is h*w
// top & bottom
for (int c = 0; c < 2 * w; c++) {
mvaddch(y, x + c + 1, ACS_HLINE);
mvaddch(y + h + 1, x + c + 1, ACS_HLINE);
}
// left & right
for (int r = 0; r < h; r++) {
mvaddch(y + r + 1, x, ACS_VLINE);
mvaddch(y + r + 1, x + 2 * w + 1, ACS_VLINE);
}
// corners
mvaddch(y, x, ACS_ULCORNER);
mvaddch(y, x + 2 * w + 1, ACS_URCORNER);
mvaddch(y + h + 1, x, ACS_LLCORNER);
mvaddch(y + h + 1, x + 2 * w + 1, ACS_LRCORNER);
refresh();
}
void printmap(char** map, int y, int x, int mapH, int mapW) {
for (int r = 0; r < mapH; r++) {
for (int c = 0; c < mapW; c++) {
if (map[r][c] == '+') {
mvaddch(y + r + 1, x + 2 * c + 1, (' ' | A_REVERSE));
addch(' ' | A_REVERSE);
}
}
}
refresh();
}
void printpieces(struct piece** hand, int y, int x, int nhand) {
for (int i = 0; i < nhand; i++) {
if (hand[i] == NULL)
continue;
struct piece* pc = hand[i];
move(y, x);
printw("%d", i);
printrect(y + 1, x, pc->h + 2, pc->w + 2);
for (int r = 0; r < pc->h; r++) {
for (int c = 0; c < pc->w; c++) {
if (pc->blocks[r * pc->w + c] == '+') {
mvaddch(y + r + 3, x + 2 * c + 3, (' '| A_REVERSE));
addch(' ' | A_REVERSE);
}
}
}
x += 2 * pc->w + 8;
}
refresh();
}
|