aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-04-11 14:03:51 +0300
committereug-vs <eugene@eug-vs.xyz>2022-04-11 14:03:51 +0300
commit5fdb5f76f40a33a913cf2c02fdd67386e4c3552f (patch)
tree6ee762e5e806a6126949e5c57a2c259be540cc6d
parent221949ecfaaefece1767cc1634c3bc3081c0bd1d (diff)
downloadcarcassonne-engine-c-5fdb5f76f40a33a913cf2c02fdd67386e4c3552f.tar.gz
feat: highlight available tile placements
-rw-r--r--src/board.h1
-rw-r--r--src/main.c9
2 files changed, 9 insertions, 1 deletions
diff --git a/src/board.h b/src/board.h
index 3d3fdc2..a8505e5 100644
--- a/src/board.h
+++ b/src/board.h
@@ -13,6 +13,7 @@ typedef struct {
static const char EMPTY = ' ';
static const char ANY = '*';
static const char SEPARATOR = '+';
+static const char PREVIEW_AVAILABLE = '@';
static const int NEIGHBOR_INCREMENTS[] = { -BOARD_ROW_UNITS, 1, BOARD_ROW_UNITS, -1 };
diff --git a/src/main.c b/src/main.c
index 4f60ba1..170ffea 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,8 +49,15 @@ int main() {
board_preview[i].feature = board[i].feature;
board_preview[i].structure_group = board[i].structure_group;
}
- place_tile(tile, translate_coordinate(position), board_preview, 1);
+ /* highlight available placements */
+ for (int k = 0; k < BOARD_WIDTH * BOARD_WIDTH; k++) {
+ if (is_allowed_placement(tile, translate_coordinate(k), board)) {
+ board_preview[translate_coordinate(k)].feature = PREVIEW_AVAILABLE;
+ }
+ }
+
+ place_tile(tile, translate_coordinate(position), board_preview, 1);
int is_allowed = is_allowed_placement(tile, translate_coordinate(position), board);
if (is_allowed) wattron(board_win, COLOR_PAIR(2));