diff options
| author | Mario Kilies <MarioKilies@GMX.net> | 2011-01-14 04:32:35 +0100 |
|---|---|---|
| committer | Mario Kilies <MarioKilies@GMX.net> | 2011-01-14 04:32:35 +0100 |
| commit | 9c855d16f1a737ddd9bde72e0fc51f4fd0a1e042 (patch) | |
| tree | 6d7f46a8aef12232c7ffd12fc9369d3f339444f6 | |
| parent | 0dfe9ff514cb6e3ffe9bfd394aebeb54445edc03 (diff) | |
Implemented hand_sort(). ui_choose_card() now pre-selects the card with lowest index, if at index 0 is no card. draw_card() now draws empty placeholder cards, to clear old screen content.
| -rw-r--r-- | src/hand.c | 16 | ||||
| -rw-r--r-- | src/hand.h | 2 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/ui.c | 30 | ||||
| -rw-r--r-- | src/ui.h | 2 |
5 files changed, 44 insertions, 8 deletions
diff --git a/src/hand.c b/src/hand.c new file mode 100644 index 0000000..8c2a392 --- /dev/null +++ b/src/hand.c @@ -0,0 +1,16 @@ +#include "hand.h" +#include <stdlib.h> +#include "card.h" + +static int hand_comparator(const void *a, const void *b) +{ + card c1 = *(card *)a; + card c2 = *(card *)b; + + return c1 - c2; +} + +void hand_sort(hand h) +{ + qsort(h, MAX_HAND_CARDS, sizeof(card), hand_comparator); +} @@ -7,4 +7,6 @@ typedef card hand[MAX_HAND_CARDS]; +void hand_sort(hand h); + #endif // OXEN_HAND_H @@ -26,7 +26,7 @@ int main(int argc, char **argv) const uint32_t score = 10; // Example data set for hand cards window - const hand h = {12, 0, 22, 25, 27, 69, 77, 85, 100, 103}; + hand h = {22, 0, 12, 85, 27, 69, 78, 0, 77, 0}; ui_init(); ui_display_wnd_table_cards(ts, false, 0); @@ -26,6 +26,17 @@ static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const boo { unsigned color_pair = 0; + // If card is 0, draw a placeholder (empty space) instead of a card. This is used to remove a card that does not longer exist but has visible remains on the screen. + if (0 == c) + { + mvwhline(w, row, col, ' ', 7); + mvwhline(w, row+1, col, ' ', 7); + mvwhline(w, row+2, col, ' ', 7); + mvwhline(w, row+3, col, ' ', 7); + mvwhline(w, row+4, col, ' ', 7); + return; + } + if (highlight) wattron(w, A_BOLD); @@ -231,10 +242,6 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t for (uint8_t i = 0; i < MAX_HAND_CARDS; i++) { - // Skip empty card slots in hand - if (0 == h[i]) - continue; - if (highlight && i == highlighted_card) { if (i < 5) // Start with the first row of cards @@ -253,16 +260,27 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t wrefresh(w_hand_cards); } -uint8_t ui_choose_card(const hand h) +uint8_t ui_choose_card(hand h) { int key; uint8_t chosen_card_idx = 0; + int8_t i; // Has to be signed for modulo calculation + + hand_sort(h); + + // Select card with lowest index as default + if (0 == h[chosen_card_idx]) + { + i = (chosen_card_idx + 1) % MAX_HAND_CARDS; + while(0 == h[i]) + i = (i + 1) % MAX_HAND_CARDS; + chosen_card_idx = i; + } ui_display_wnd_hand_cards(h, true, chosen_card_idx); while (KEY_RETURN != (key = wgetch(w_hand_cards))) { - int8_t i; // Has to be signed for modulo calculation switch (key) { case KEY_VI_LEFT: @@ -12,7 +12,7 @@ void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, cons void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, const uint8_t highlighted_points); void ui_display_wnd_current_state(const player_name_open_card_tuple pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score); void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t highlighted_card); -uint8_t ui_choose_card(const hand h); +uint8_t ui_choose_card(hand h); uint8_t ui_choose_stack(const tablestacks ts); void ui_init(void); void ui_fini(void); |
