#include #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, x + 2 * c, (' ' | A_REVERSE)); addch(' ' | A_REVERSE); } else { mvaddch(y + r, x + 2 * c, (' ')); addch(' '); } } } refresh(); } void printpiece(struct piece* pc, int y, int x, int color_pair) { attron(COLOR_PAIR(color_pair)); 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, x + 2 * c, (' ' | A_REVERSE)); addch(' ' | A_REVERSE); } } } attroff(COLOR_PAIR(color_pair)); refresh(); } void printpieces(struct piece** hand, int y, int x, int nhand, int highlight) { for (int i = 0; i < nhand; i++) { if (hand[i] == NULL) continue; struct piece* pc = hand[i]; printpiece(pc, y + 2, x + 3, (i == highlight ? 1 : 0)); x += 2 * pc->w + 8; } refresh(); }