diff options
| -rw-r--r-- | src/main.c | 3 | ||||
| -rw-r--r-- | src/pnoc.c | 15 | ||||
| -rw-r--r-- | src/pnoc.h (renamed from src/player_name_open_card_tuple.h) | 10 | ||||
| -rw-r--r-- | src/ui.c | 2 | ||||
| -rw-r--r-- | src/ui.h | 4 |
5 files changed, 26 insertions, 8 deletions
@@ -10,7 +10,7 @@ int main(int argc, char **argv) // The stack points window uses ts, too, so there is no separate data set // Example data set for current state window - const player_name_open_card_tuple pnoc[10] = { + pnoc_t pnoc[10] = { {"$you", 10}, {"1234567890", 23}, {"baz", 38}, @@ -22,6 +22,7 @@ int main(int argc, char **argv) {"hornoxe", 33}, {"1337nick", 74} }; + pnoc_sort(pnoc, 10); const uint8_t num_players = 10; const uint32_t score = 10; diff --git a/src/pnoc.c b/src/pnoc.c new file mode 100644 index 0000000..0bfacad --- /dev/null +++ b/src/pnoc.c @@ -0,0 +1,15 @@ +#include "pnoc.h" +#include <stdlib.h> + +static int pnoc_comparator(const void *a, const void *b) +{ + pnoc_t pnoc1 = *(pnoc_t *)a; + pnoc_t pnoc2 = *(pnoc_t *)b; + + return pnoc1.open_card - pnoc2.open_card; +} + +void pnoc_sort(pnoc_t pnoc[], const uint8_t num_tuples) +{ + qsort(pnoc, num_tuples, sizeof(pnoc_t), pnoc_comparator); +} diff --git a/src/player_name_open_card_tuple.h b/src/pnoc.h index b856e80..bfff947 100644 --- a/src/player_name_open_card_tuple.h +++ b/src/pnoc.h @@ -1,5 +1,5 @@ -#ifndef OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H -#define OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H +#ifndef OXEN_PNOC_H +#define OXEN_PNOC_H #include "player.h" #include "card.h" @@ -8,6 +8,8 @@ typedef struct { char player_name[MAX_PLAYER_NAME_LENGTH+1]; // Player name length + 1 for string termination card open_card; -} player_name_open_card_tuple; +} pnoc_t; -#endif // OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H +void pnoc_sort(pnoc_t pnoc[], const uint8_t num_tuples); + +#endif // OXEN_PNOC_H @@ -202,7 +202,7 @@ void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, con * @param[in] active_players The currently active player * @param[in] score The players score */ -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_current_state(const pnoc_t pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score) { wattron(w_current_state, A_BOLD); mvwprintw(w_current_state, 0, 0, "Current state:"); @@ -6,11 +6,11 @@ #include "cardstack.h" #include "tablestacks.h" #include "hand.h" -#include "player_name_open_card_tuple.h" +#include "pnoc.h" void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, const uint8_t highlighted_stack); 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_current_state(const pnoc_t 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(hand h); uint8_t ui_choose_stack(const tablestacks ts); |
