From cecf821c9526ba2e93288f4f0ff354b2cb98c452 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 10 Apr 2022 22:32:36 +0300 Subject: feat: highlight player-controlled areas --- src/main.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 5001ba6..595d97a 100644 --- a/src/main.c +++ b/src/main.c @@ -3,13 +3,21 @@ #include #include "board.h" -void draw_board(BoardUnit* board, WINDOW* win) { +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 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 | COLOR_PAIR(board[index].structure_group % 6)); + else waddch( + win, + board[index].feature + | get_player_color(get_structure_dominator(board[index].structure_group, meeple_map)) + ); } } wrefresh(win); @@ -40,6 +48,7 @@ int main() { wrefresh(messages_box); + int meeple_map[MAX_STRUCTURES * PLAYERS]; BoardUnit board[BOARD_UNITS]; initialize_board(board); @@ -59,7 +68,8 @@ int main() { for (int move = 0; ; move++) { /* board */ refresh_structure_groups(board); - draw_board(board, board_win); + refresh_meeple_map(board, meeple_map); + draw_board(board, meeple_map, board_win); /* tile placement */ tile = tileset[rand() % 5]; @@ -76,7 +86,7 @@ int main() { int is_allowed = is_allowed_placement(tile, translate_coordinate(position), board); if (is_allowed) wattron(board_win, COLOR_PAIR(2)); - draw_board(board_preview, board_win); + draw_board(board_preview, meeple_map, board_win); wattroff(board_win, COLOR_PAIR(2)); input_key = wgetch(board_win); @@ -96,6 +106,8 @@ int main() { if (result) wprintw(messages_win, "Placed tile %s (%c) at position %i\n", tile.edges, tile.center, position); else wprintw(messages_win, "Could not place tile %s (%c) at position %i\n", tile.edges, tile.center, position); + refresh_structure_groups(board); + refresh_meeple_map(board, meeple_map); /* meeple placement */ input_key = wgetch(board_win); @@ -108,8 +120,11 @@ int main() { else if (input_key != 10) meeple_index = -1; if (meeple_index >= 0) { - board[meeple_index].meeple = move % PLAYERS; - wprintw(messages_win, "Placed meeple #%i at index %i\n", move % PLAYERS, meeple_index); + int meeple = (move % PLAYERS) + 1; + if (is_allowed_meeple(meeple, meeple_index, board, meeple_map)) { + board[meeple_index].meeple = meeple; + wprintw(messages_win, "Placed meeple #%i at index %i\n", meeple, meeple_index); + } else wprintw(messages_win, "Could not place meeple #%i at index %i\n", meeple, meeple_index); } wrefresh(messages_win); -- cgit v1.2.3