diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-03-31 22:36:17 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-03-31 22:36:17 +0300 |
commit | 33d4ede846df55578bcdbe9ce5907e0b6d6e304b (patch) | |
tree | f4849c0a09867211cdc60c663d59182e492f7660 /src/main.c | |
parent | c5418464d57de2b71a91ddfbb4c42df25a743da9 (diff) | |
download | carcassonne-engine-c-33d4ede846df55578bcdbe9ce5907e0b6d6e304b.tar.gz |
refactor: merge structures into board
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 43 |
1 files changed, 26 insertions, 17 deletions
@@ -3,13 +3,24 @@ #include <curses.h> #include "board.h" -void draw_board(char* board, WINDOW* win) { +void draw_board(BoardUnit* board, WINDOW* win) { wmove(win, 0, 0); - for (int row = 0; row < BOARD_ROW_BYTES; row++) { - for (int i = 0; i < BOARD_ROW_BYTES; i++) { - int index = BOARD_ROW_BYTES * row + i; - if (board[index] == EMPTY && is_center_index(index)) waddch(win, '*'); - else waddch(win, board[index]); + for (int row = 0; row < BOARD_ROW_UNITS; row++) { + for (int i = 0; i < BOARD_ROW_UNITS; i++) { + int index = BOARD_ROW_UNITS * row + i; + if (board[index].feature == EMPTY && is_center_index(index)) waddch(win, '*'); + else waddch(win, board[index].feature); + } + } +} + +void draw_structures(BoardUnit* board, WINDOW* win) { + wmove(win, 0, 0); + for (int row = 0; row < BOARD_ROW_UNITS; row++) { + for (int i = 0; i < BOARD_ROW_UNITS; i++) { + int index = BOARD_ROW_UNITS * row + i; + if (board[index].feature == EMPTY && is_center_index(index)) waddch(win, '*'); + else waddch(win, board[index].structure_group == 0 ? ' ' : '0' + board[index].structure_group); } } } @@ -20,32 +31,31 @@ int main() { cbreak(); /* create board window */ - WINDOW* board_box = newwin(BOARD_ROW_BYTES + 2, BOARD_ROW_BYTES + 2, 0, 0); - WINDOW* board_win = derwin(board_box, BOARD_ROW_BYTES, BOARD_ROW_BYTES, 1, 1); + WINDOW* board_box = newwin(BOARD_ROW_UNITS + 2, BOARD_ROW_UNITS + 2, 0, 0); + WINDOW* board_win = derwin(board_box, BOARD_ROW_UNITS, BOARD_ROW_UNITS, 1, 1); box(board_box, 0, 0); wrefresh(board_box); /* create structures window */ - WINDOW* structures_box = newwin(BOARD_ROW_BYTES + 2, BOARD_ROW_BYTES + 2, 0, BOARD_ROW_BYTES + 3); - WINDOW* structures_win = derwin(structures_box, BOARD_ROW_BYTES, BOARD_ROW_BYTES, 1, 1); + WINDOW* structures_box = newwin(BOARD_ROW_UNITS + 2, BOARD_ROW_UNITS + 2, 0, BOARD_ROW_UNITS + 3); + WINDOW* structures_win = derwin(structures_box, BOARD_ROW_UNITS, BOARD_ROW_UNITS, 1, 1); box(structures_box, 0, 0); wrefresh(structures_box); /* create input window */ - WINDOW* input_box = newwin(3, 22, BOARD_ROW_BYTES + 3, 0); + WINDOW* input_box = newwin(3, 22, BOARD_ROW_UNITS + 3, 0); WINDOW* input_win = derwin(input_box, 1, 20, 1, 1); box(input_box, 0, 0); wrefresh(input_box); /* create messages window */ - WINDOW* messages_box = newwin(40, 60, BOARD_ROW_BYTES + 6, 0); + WINDOW* messages_box = newwin(40, 60, BOARD_ROW_UNITS + 6, 0); WINDOW* messages_win = derwin(messages_box, 40 - 2, 60 - 2, 1, 1); box(messages_box, 0, 0); wrefresh(messages_box); - char board[BOARD_BYTES]; - char structures[BOARD_BYTES]; + BoardUnit board[BOARD_UNITS]; initialize_board(board); Tile tile = { "FRCR", 'R', 0 }; @@ -56,13 +66,12 @@ int main() { while (1) { /* prepare */ - initialize_board(structures); - create_structure_mask(board, structures); + refresh_structure_groups(board); wclear(input_win); /* draw onto the screen */ draw_board(board, board_win); - draw_board(structures, structures_win); + draw_structures(board, structures_win); wrefresh(board_win); wrefresh(structures_win); |