diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 45 | 
1 files changed, 38 insertions, 7 deletions
| @@ -25,6 +25,14 @@ void draw_structures(BoardUnit* board, WINDOW* win) {    }  } +void preview_tile(Tile tile, WINDOW* win) { +  mvwaddch(win, 1, 1, tile.center); +  mvwaddch(win, 0, 1, tile.edges[0]); +  mvwaddch(win, 1, 2, tile.edges[1]); +  mvwaddch(win, 2, 1, tile.edges[2]); +  mvwaddch(win, 1, 0, tile.edges[3]); +} +  int main() {    /* initialize curses */    initscr(); @@ -48,6 +56,12 @@ int main() {    box(input_box, 0, 0);    wrefresh(input_box); +  /* create tile inspector window */ +  WINDOW* tile_box = newwin(5, 5, BOARD_ROW_UNITS + 3, 60); +  WINDOW* tile_win = derwin(tile_box, 3, 3, 1, 1); +  box(tile_box, 0, 0); +  wrefresh(tile_box); +    /* create messages window */    WINDOW* messages_box = newwin(40, 60, BOARD_ROW_UNITS + 6, 0);    WINDOW* messages_win = derwin(messages_box, 40 - 2, 60 - 2, 1, 1); @@ -58,11 +72,18 @@ int main() {    BoardUnit board[BOARD_UNITS];    initialize_board(board); +  Tile tileset[3] = { +    { "RRRR", 'R', 0 }, +    { "FCCC", 'C', 0 }, +    { "FFFC", 'C', 0 } +  }; +    Tile tile = { "FRCR", 'R', 0 };    place_tile(tile, translate_coordinate(24), board, 1);    /* main loop */    char position[3]; +  char rotation_input;    while (1) {      /* prepare */      refresh_structure_groups(board); @@ -74,18 +95,28 @@ int main() {      wrefresh(board_win);      wrefresh(structures_win); -    /* user input */ -    box(input_box, 0, 0); -    mvwaddstr(input_box, 0, 0, "Enter tile:"); -    wrefresh(input_box); -    wgetnstr(input_win, tile.edges, 5); -    wclear(input_win); -    if (tile.edges[0] == 'q') break; +    /* tile pickup */ +    tile = tileset[rand() % 3]; + +    while (1) { +      preview_tile(tile, tile_win); +      wrefresh(tile_win); +      rotation_input = wgetch(tile_win); +      if (rotation_input == 10) break; /* enter key */ +      else if (rotation_input == 'j') rotate_tile(&tile, 1); +      else if (rotation_input == 'k') rotate_tile(&tile, 3); +    } + +    /* position prompt */ +    echo();      box(input_box, 0, 0);      mvwaddstr(input_box, 0, 0, "Enter position:");      wrefresh(input_box);      wgetnstr(input_win, position, 3); +    noecho(); + +    if (position[0] == 'q') break;      int result = place_tile(tile, translate_coordinate(atoi(position)), board, 0);      if (result) wprintw(messages_win, "Placed tile %s (%c) at position %i\n", tile.edges, tile.center, atoi(position)); | 
