diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -29,33 +29,43 @@ int main() { /* initialize curses */ initscr(); cbreak(); + use_default_colors(); + + /* colors */ + start_color(); + init_pair(1, COLOR_GREEN, COLOR_BLACK); /* create board window */ 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); + mvwaddstr(board_box, 0, 1, "Board"); wrefresh(board_box); /* create structures window */ 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); + mvwaddstr(structures_box, 0, 1, "Structures"); wrefresh(structures_box); /* create messages window */ WINDOW* messages_box = newwin(40, 60, BOARD_ROW_UNITS + 2, 0); WINDOW* messages_win = derwin(messages_box, 40 - 2, 60 - 2, 1, 1); box(messages_box, 0, 0); + mvwaddstr(messages_box, 0, 1, "Log"); wrefresh(messages_box); BoardUnit board[BOARD_UNITS]; initialize_board(board); - Tile tileset[3] = { + Tile tileset[5] = { { "RRRR", 'R', 0 }, { "FCCC", 'C', 0 }, - { "FFFC", 'C', 0 } + { "FFFC", 'C', 0 }, + { "CCRR", 'C', 0 }, + { "RFRF", 'R', 0 } }; Tile tile = { "FRCR", 'R', 0 }; @@ -74,7 +84,7 @@ int main() { wrefresh(structures_win); /* tile placement */ - tile = tileset[rand() % 3]; + tile = tileset[rand() % 5]; int position = 0; BoardUnit board_preview[BOARD_UNITS]; @@ -83,16 +93,26 @@ int main() { board_preview[i].feature = board[i].feature; } 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(1)); + else wattroff(board_win, COLOR_PAIR(1)); + draw_board(board_preview, board_win); wrefresh(board_win); input_key = wgetch(board_win); - if (input_key == 10) break; /* enter key */ + if (input_key == 10 && is_allowed) break; /* enter key */ else if (input_key == 'l') position += 1; else if (input_key == 'h') position -= 1; 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); |