From 5f583e476f3f711a581f417319670ee401a716c4 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 10 Apr 2022 21:19:09 +0300 Subject: feat: add meeple placement --- src/main.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index ab5409e..5001ba6 100644 --- a/src/main.c +++ b/src/main.c @@ -56,14 +56,10 @@ int main() { /* main loop */ char input_key; - while (1) { + for (int move = 0; ; move++) { /* board */ refresh_structure_groups(board); draw_board(board, board_win); - if (wgetch(board_win) == 'q') { - endwin(); - return 0; - } /* tile placement */ tile = tileset[rand() % 5]; @@ -90,11 +86,32 @@ int main() { else if (input_key == 'j') position += BOARD_WIDTH; else if (input_key == 'k') position -= BOARD_WIDTH; else if (input_key == 'r') rotate_tile(&tile, 3); + else if (input_key == 'q') { + endwin(); + return 0; + } } int result = place_tile(tile, translate_coordinate(position), board, 0); 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); + + + /* meeple placement */ + input_key = wgetch(board_win); + int meeple_index = translate_coordinate(position); + + if (input_key == 'l') meeple_index += 1; + else if (input_key == 'h') meeple_index -= 1; + else if (input_key == 'j') meeple_index += BOARD_ROW_UNITS; + else if (input_key == 'k') meeple_index -= BOARD_ROW_UNITS; + 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); + } + wrefresh(messages_win); } -- cgit v1.2.3