diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-11 11:40:01 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-11 11:40:01 +0300 |
commit | 28d65efb66a2fb068ed9d5be082fa5167007d731 (patch) | |
tree | f6c76dc7c7170b73c3d879bba32278be4c5fdf76 /src/gui.c | |
parent | a6dc21034a55be0a9c1910787d615b5bca7131c6 (diff) | |
download | carcassonne-engine-c-28d65efb66a2fb068ed9d5be082fa5167007d731.tar.gz |
refactor: move GUI to separate files
Diffstat (limited to 'src/gui.c')
-rw-r--r-- | src/gui.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gui.c b/src/gui.c new file mode 100644 index 0000000..29ad554 --- /dev/null +++ b/src/gui.c @@ -0,0 +1,34 @@ +#include "gui.h" +#include "meeple.h" + +void initialize_colors() { + use_default_colors(); + start_color(); + for (int i = 1; i < 6; i++) init_pair(i, COLOR_BLACK + i, COLOR_BLACK); +} + +int get_player_color(int player) { + return player ? COLOR_PAIR(player + 2) : COLOR_PAIR(0); +} + +void draw_board(BoardUnit* board, int* meeple_map, WINDOW* win) { + wmove(win, 0, 0); + for (int i = 0; i < BOARD_UNITS; i++) { + if (board[i].feature == EMPTY && is_center_index(i)) waddch(win, '.'); + else waddch( + win, + board[i].feature + | get_player_color(get_structure_dominator(board[i].structure_group, meeple_map)) + ); + } + wrefresh(win); +} + +WINDOW* create_framed_window(char* name, int lines, int cols, int x, int y) { + WINDOW* frame = newwin(lines, cols, x, y); + WINDOW* window = derwin(frame, lines - 2, cols - 2, 1, 1); + box(frame, 0, 0); + mvwaddstr(frame, 0, 1, name); + wrefresh(frame); + return window; +} |