summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hand.c16
-rw-r--r--src/hand.h2
-rw-r--r--src/main.c2
-rw-r--r--src/ui.c30
-rw-r--r--src/ui.h2
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);
+}
diff --git a/src/hand.h b/src/hand.h
index f9feb6e..83c3160 100644
--- a/src/hand.h
+++ b/src/hand.h
@@ -7,4 +7,6 @@
typedef card hand[MAX_HAND_CARDS];
+void hand_sort(hand h);
+
#endif // OXEN_HAND_H
diff --git a/src/main.c b/src/main.c
index 81b142e..388f34d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
diff --git a/src/ui.c b/src/ui.c
index 7c8f8f2..e7b7657 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -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:
diff --git a/src/ui.h b/src/ui.h
index ea1c1d6..2d38654 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -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);