diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 55 |
1 files changed, 16 insertions, 39 deletions
@@ -9,20 +9,10 @@ void draw_board(BoardUnit* board, WINDOW* win) { 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); - } - } -} - -void draw_structures(BoardUnit* board, 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].structure_group == 0 ? EMPTY : '0' + board[index].structure_group); + else waddch(win, board[index].feature | COLOR_PAIR(board[index].structure_group % 6)); } } + wrefresh(win); } int main() { @@ -33,7 +23,7 @@ int main() { /* colors */ start_color(); - init_pair(1, COLOR_GREEN, COLOR_BLACK); + for (int i = 1; i < 6; i++) init_pair(i, COLOR_BLACK + i, COLOR_BLACK); /* create board window */ WINDOW* board_box = newwin(BOARD_ROW_UNITS + 2, BOARD_ROW_UNITS + 2, 0, 0); @@ -42,16 +32,9 @@ int main() { 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); + WINDOW* messages_box = newwin(BOARD_ROW_UNITS + 2, 60, 0, BOARD_ROW_UNITS + 3); + WINDOW* messages_win = derwin(messages_box, BOARD_ROW_UNITS, 60 - 2, 1, 1); box(messages_box, 0, 0); mvwaddstr(messages_box, 0, 1, "Log"); wrefresh(messages_box); @@ -60,6 +43,9 @@ int main() { BoardUnit board[BOARD_UNITS]; initialize_board(board); + Tile tile = { "FRCR", 'R', 0 }; + place_tile(tile, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1); + Tile tileset[5] = { { "RRRR", 'R', 0 }, { "FCCC", 'C', 0 }, @@ -68,20 +54,16 @@ int main() { { "RFRF", 'R', 0 } }; - Tile tile = { "FRCR", 'R', 0 }; - place_tile(tile, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1); - /* main loop */ char input_key; while (1) { - /* prepare */ + /* board */ refresh_structure_groups(board); - - /* draw onto the screen */ draw_board(board, board_win); - draw_structures(board, structures_win); - wrefresh(board_win); - wrefresh(structures_win); + if (wgetch(board_win) == 'q') { + endwin(); + return 0; + } /* tile placement */ tile = tileset[rand() % 5]; @@ -91,16 +73,15 @@ int main() { while (1) { for (int i = 0; i < BOARD_UNITS; i++) { 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); 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)); - + if (is_allowed) wattron(board_win, COLOR_PAIR(2)); draw_board(board_preview, board_win); - wrefresh(board_win); + wattroff(board_win, COLOR_PAIR(2)); input_key = wgetch(board_win); if (input_key == 10 && is_allowed) break; /* enter key */ @@ -109,10 +90,6 @@ 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); |