From fac5e3de0929c3abb73da552efbda6d641136588 Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Sun, 16 Jan 2011 07:57:28 +0100 Subject: Simplified net_recv(). Refactored 'hand' from array definition to hand_t struct definition. --- src/ui.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/ui.c') diff --git a/src/ui.c b/src/ui.c index ee27567..a42ecf4 100644 --- a/src/ui.c +++ b/src/ui.c @@ -241,7 +241,7 @@ void ui_display_wnd_current_state(const pnoc_t pnoc[], const uint8_t num_players * @param[in] highlight If true, a card will be highlighted * @param[in] highlighted_card The card to highlight. Only used, if highlight is true */ -void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t highlighted_card) +void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint8_t highlighted_card) { uint8_t num_zero_cards = 0; @@ -249,7 +249,7 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t mvwprintw(w_hand_cards, 0, 0, "Hand Cards:"); wattroff(w_hand_cards, A_BOLD); - // Clear old cards from screen first + // Clear old cards from screen first by drawing emtpy card placeholders over them for (uint8_t i = 0; i < MAX_HAND_CARDS; i++) { if (i - num_zero_cards < 5) // Start with the first row of cards @@ -261,7 +261,7 @@ 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++) { // Cound all 0 cards and don't draw them - if (0 == h[i]) + if (0 == h->cards[i]) { num_zero_cards++; continue; @@ -270,22 +270,22 @@ void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t if (highlight && i == highlighted_card) { if (i - num_zero_cards < 5) // Start with the first row of cards - draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, true, h[i]); + draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, true, h->cards[i]); else // And then draw the second row - draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, true, h[i]); + draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, true, h->cards[i]); continue; } if (i - num_zero_cards < 5) // Start with the first row of cards - draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, false, h[i]); + draw_card(w_hand_cards, 1, (i - num_zero_cards) * 8, false, h->cards[i]); else // And then draw the second row - draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, false, h[i]); + draw_card(w_hand_cards, 6, (i - num_zero_cards - 5) * 8, false, h->cards[i]); } wrefresh(w_hand_cards); } -uint8_t ui_choose_card(hand h) +uint8_t ui_choose_card(hand_t *h) { int key; uint8_t chosen_card_idx = 0; @@ -294,10 +294,10 @@ uint8_t ui_choose_card(hand h) hand_sort(h); // Select card with lowest index as default - if (0 == h[chosen_card_idx]) + if (0 == h->cards[chosen_card_idx]) { i = (chosen_card_idx + 1) % MAX_HAND_CARDS; - while(0 == h[i]) + while(0 == h->cards[i]) i = (i + 1) % MAX_HAND_CARDS; chosen_card_idx = i; } @@ -311,8 +311,9 @@ uint8_t ui_choose_card(hand h) case KEY_VI_LEFT: // Fall through case KEY_LEFT: + // Add MAX_HAND_CARDS to prevent calculating the modulus of negative values i = (chosen_card_idx - 1 + MAX_HAND_CARDS) % MAX_HAND_CARDS; - while(0 == h[i]) + while(0 == h->cards[i]) i = (i - 1 + MAX_HAND_CARDS) % MAX_HAND_CARDS; chosen_card_idx = i; break; @@ -321,7 +322,7 @@ uint8_t ui_choose_card(hand h) // Fall through case KEY_RIGHT: i = (chosen_card_idx + 1) % MAX_HAND_CARDS; - while(0 == h[i]) + while(0 == h->cards[i]) i = (i + 1) % MAX_HAND_CARDS; chosen_card_idx = i; break; -- cgit v1.2.3