diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-11 13:48:24 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-11 13:48:24 +0300 |
commit | 221949ecfaaefece1767cc1634c3bc3081c0bd1d (patch) | |
tree | 7dc19941be4ac9385c3944d749e16c1d1775ccd9 | |
parent | 708c9a4c65e943ca55a7d31d1826c42650139b50 (diff) | |
download | carcassonne-engine-c-221949ecfaaefece1767cc1634c3bc3081c0bd1d.tar.gz |
feat: add scrolling and available meeples counter
-rw-r--r-- | src/main.c | 28 | ||||
-rw-r--r-- | src/meeple.c | 8 | ||||
-rw-r--r-- | src/meeple.h | 3 |
3 files changed, 27 insertions, 12 deletions
@@ -15,22 +15,30 @@ int main() { WINDOW* board_win = create_framed_window("Board", BOARD_ROW_UNITS + 2, BOARD_ROW_UNITS + 2, 0, 0); WINDOW* messages_win = create_framed_window("Log", BOARD_ROW_UNITS + 2, 80, 0, BOARD_ROW_UNITS + 3); + scrollok(messages_win, 1); - int meeple_map[MAX_STRUCTURES * PLAYERS]; BoardUnit board[BOARD_UNITS]; - initialize_board(board); + int available_meeples[PLAYERS]; + int meeple_map[MAX_STRUCTURES * PLAYERS]; + Tile tile; - Tile tile = { "FRCR", 'R', 0 }; - place_tile(tile, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1); + initialize_board(board); + initialize_available_meeples(available_meeples); + place_tile((Tile){ "FRCR", 'R', 0 }, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1); /* main loop */ char input_key; for (int move = 0; ; move++) { + int player = (move % PLAYERS) + 1; /* board */ refresh_structure_groups(board); refresh_meeple_map(board, meeple_map); draw_board(board, meeple_map, board_win); + wattron(messages_win, get_player_color(player)); + wprintw(messages_win, "Move %i, (player #%i, %i meeples available)\n", move, player, available_meeples[player - 1]); + wrefresh(messages_win); + /* tile placement */ tile = TILESET[rand() % 19]; int position = 0; @@ -79,12 +87,12 @@ int main() { else if (input_key == 'k') meeple_index -= BOARD_ROW_UNITS; else if (input_key != 10) meeple_index = -1; - if (meeple_index >= 0) { - 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); + if (meeple_index >= 0 && available_meeples[player - 1] > 0) { + if (is_allowed_meeple(player, meeple_index, board, meeple_map)) { + board[meeple_index].meeple = player; + available_meeples[player - 1]--; + wprintw(messages_win, "Placed meeple at %c\n", board[meeple_index].feature); + } else wprintw(messages_win, "Could not place meeple at %c\n", board[meeple_index].feature); } wrefresh(messages_win); diff --git a/src/meeple.c b/src/meeple.c index b9df686..ea70ec2 100644 --- a/src/meeple.c +++ b/src/meeple.c @@ -1,10 +1,13 @@ #include "meeple.h" +void initialize_available_meeples(int* available_meeples) { + for (int i = 0; i < PLAYERS; i++) available_meeples[i] = PLAYER_MEEPLES; +} + void refresh_meeple_map(BoardUnit* board, int* meeple_map) { for (int i = 0; i < MAX_STRUCTURES * PLAYERS; i++) meeple_map[i] = 0; - for (int i = 0; i < BOARD_UNITS; i++) { - if (board[i].meeple) { + for (int i = 0; i < BOARD_UNITS; i++) { if (board[i].meeple) { meeple_map[board[i].structure_group * PLAYERS + (board[i].meeple - 1)]++; } } @@ -34,3 +37,4 @@ int get_structure_dominator(int structure_group, int* meeple_map) { } return dominator; } + diff --git a/src/meeple.h b/src/meeple.h index 5a7df20..7aff946 100644 --- a/src/meeple.h +++ b/src/meeple.h @@ -1,6 +1,9 @@ #pragma once #include "structure.h" +#define PLAYER_MEEPLES 7 + +void initialize_available_meeples(int* available_meeples); int is_allowed_meeple(int meeple, int index, BoardUnit* board, int* meeple_map); void refresh_meeple_map(BoardUnit* board, int* meeple_map); int get_structure_dominator(int structure_group, int* meeple_map); |