diff options
Diffstat (limited to 'src/display.c')
| -rw-r--r-- | src/display.c | 105 |
1 files changed, 94 insertions, 11 deletions
diff --git a/src/display.c b/src/display.c index 8ed3d73..f9730dc 100644 --- a/src/display.c +++ b/src/display.c @@ -8,8 +8,12 @@ #define CP_RED_ON_BLACK 5 static bool colors = false; +static WINDOW *w_table_cards; +static WINDOW *w_stack_points; +static WINDOW *w_current_state; +static WINDOW *w_hand_cards; -void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const card c) +static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const card c) { unsigned color_pair = 0; @@ -33,7 +37,7 @@ void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const color_pair = CP_WHITE_ON_BLACK; } - attron(COLOR_PAIR(color_pair)); + wattron(w, COLOR_PAIR(color_pair)); } mvwaddch(w, row, col, ACS_ULCORNER); // Upper left corner @@ -89,10 +93,76 @@ void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const if (colors) { - attroff(COLOR_PAIR(color_pair)); + wattroff(w, COLOR_PAIR(color_pair)); } } +static void draw_cardstack(WINDOW *w, const uint8_t row, const uint8_t col, const cardstack cs) +{ + for (uint8_t i = 0; i < MAX_CARDSTACK_SIZE; i++) + { + if (cs[i] != 0) + { + draw_card(w, row, i*2, cs[i]); + } + } +} + +void display_window_table_cards(const tablestacks ts) +{ + mvwprintw(w_table_cards, 0, 2, "Table Cards:"); + + for (uint8_t i = 0; i < NUM_TABLESTACKS; i++) + { + draw_cardstack(w_table_cards, 1 + i*5, 0, ts[i]); + } + + wrefresh(w_table_cards); +} + +void display_window_stack_points(const tablestacks ts) +{ + mvwprintw(w_stack_points, 0, 0, "Pts:"); + + for (uint8_t i = 0; i < NUM_TABLESTACKS; i++) + { + mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", i*5); + } + + wrefresh(w_stack_points); +} + +/** + * Displays the current state window. + * @param[in] score The players score +*/ +void display_window_current_state(const uint32_t score) +{ + mvwprintw(w_current_state, 0, 0, "Current state:"); + mvwprintw(w_current_state, 0, 23, "Your Score: %3d", score); + + wrefresh(w_current_state); +} + +/** + * Displays the hand cards window. + * @param[in] h The hand that will be displayed. h must not contain 0 +*/ +void display_window_hand_cards(const hand h) +{ + mvwprintw(w_hand_cards, 0, 0, "Hand Cards:"); + + for (uint8_t i = 0; i < MAX_HAND_CARDS; i++) + { + if (i < 5) // Start with the first row of cards + draw_card(w_hand_cards, 1, i*8, h[i]); + else // And then draw the second row + draw_card(w_hand_cards, 6, (i-5)*8, h[i]); + } + + wrefresh(w_hand_cards); +} + void display_init(void) { initscr(); // Start curses mode @@ -113,19 +183,32 @@ void display_init(void) nodelay(stdscr, true); // Non-blocking input noecho(); // Don't echo() while we do getch curs_set(0); // Make the cursor invisible - clear(); refresh(); - int j = 0; - for (int i = 45; i < 70; i++) - { - display_draw_card(stdscr, 0, j++*2, i+1); - usleep(750000); - refresh(); - } + + w_table_cards = newwin(21, 15, 0, 0); + w_stack_points = newwin(19, 4, 0, 17); + w_current_state = newwin(10, 38, 0, 24); + w_hand_cards = newwin(11, 39, 10, 24); + + const tablestacks ts = {{1, 2, 3, 4, 101}, {6, 7, 53, 0, 0}, {11, 55, 0, 0, 0}, {17, 29, 36, 42, 0}}; + const hand h = {12, 13, 22, 25, 27, 69, 77, 85, 100, 103}; + const uint32_t score = 10; + mvvline(0, 22, ACS_VLINE, 21); // Vertical line + refresh(); + display_window_table_cards(ts); + display_window_stack_points(ts); + display_window_current_state(score); + display_window_hand_cards(h); + //refresh(); + sleep(3); } void display_fini(void) { + delwin(w_table_cards); + delwin(w_stack_points); + delwin(w_current_state); + delwin(w_hand_cards); endwin(); // End curses mode } |
