summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client_game_states.c9
-rw-r--r--src/game.c1
-rw-r--r--src/game_states.h1
-rw-r--r--src/main_stack.h2
-rw-r--r--src/player.c19
-rw-r--r--src/player.h1
-rw-r--r--src/ui.c62
-rw-r--r--src/ui.h1
8 files changed, 93 insertions, 3 deletions
diff --git a/src/client_game_states.c b/src/client_game_states.c
index 6d39ed7..e1eb385 100644
--- a/src/client_game_states.c
+++ b/src/client_game_states.c
@@ -144,3 +144,12 @@ game_state_t state_client_play_cards(const int sock)
assert(false);
return 1337;
}
+
+void state_client_game_finished(void)
+{
+ data_store_t *d = data_store();
+
+ player_list_sort_by_score(&d->player_list, d->player_list.count); // Sort player list by scores in ascending ordner
+ ui_display_wnd_final_scores(&d->player_list, d->player_list.count, d->own_player_id);
+ ui_update();
+}
diff --git a/src/game.c b/src/game.c
index 4be4999..60b4b2b 100644
--- a/src/game.c
+++ b/src/game.c
@@ -45,6 +45,7 @@ static void main_loop_client(int sock)
break;
case STATE_CLIENT_GAME_FINISHED:
+ state_client_game_finished();
running = false;
break;
default:
diff --git a/src/game_states.h b/src/game_states.h
index 980f5ff..b7df1f5 100644
--- a/src/game_states.h
+++ b/src/game_states.h
@@ -24,6 +24,7 @@ game_state_t state_client_wait_for_hand_cards(const int sock, const uint8_t roun
game_state_t state_client_select_open_card(const int sock);
game_state_t state_client_wait_for_open_cards(const int sock);
game_state_t state_client_play_cards(const int sock);
+void state_client_game_finished(void);
game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, const uint8_t round, main_stack_t *m);
game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks);
diff --git a/src/main_stack.h b/src/main_stack.h
index aa2d420..a3ead88 100644
--- a/src/main_stack.h
+++ b/src/main_stack.h
@@ -4,7 +4,7 @@
#include <assert.h>
#include "card.h"
-#define MAX_MAIN_STACK_CARDS 104
+#define MAX_MAIN_STACK_CARDS 24
typedef struct
{
diff --git a/src/player.c b/src/player.c
index 235add8..cf587fc 100644
--- a/src/player.c
+++ b/src/player.c
@@ -16,7 +16,7 @@ player_list_entry_t *get_player_list_entry_by_player_id(player_list_t *pl, const
return NULL;
}
-static int ple_comparator(const void *a, const void *b)
+static int ple_open_card_comparator(const void *a, const void *b)
{
player_list_entry_t ple1 = *(player_list_entry_t *)a;
player_list_entry_t ple2 = *(player_list_entry_t *)b;
@@ -24,9 +24,24 @@ static int ple_comparator(const void *a, const void *b)
return ple1.open_card - ple2.open_card;
}
+static int ple_score_comparator(const void *a, const void *b)
+{
+ player_list_entry_t ple1 = *(player_list_entry_t *)a;
+ player_list_entry_t ple2 = *(player_list_entry_t *)b;
+
+ return ple1.score - ple2.score;
+}
+
void player_list_sort_by_open_card(player_list_t *pl, const uint8_t num_entries)
{
assert(pl != NULL);
- qsort(pl->players, num_entries, sizeof(player_list_entry_t), ple_comparator);
+ qsort(pl->players, num_entries, sizeof(player_list_entry_t), ple_open_card_comparator);
+}
+
+void player_list_sort_by_score(player_list_t *pl, const uint8_t num_entries)
+{
+ assert(pl != NULL);
+
+ qsort(pl->players, num_entries, sizeof(player_list_entry_t), ple_score_comparator);
}
diff --git a/src/player.h b/src/player.h
index bc72c76..920cf4d 100644
--- a/src/player.h
+++ b/src/player.h
@@ -25,5 +25,6 @@ typedef struct
player_list_entry_t *get_player_list_entry_by_player_id(player_list_t *pl, const player_id_t pid);
void player_list_sort_by_open_card(player_list_t *pl, const uint8_t num_entries);
+void player_list_sort_by_score(player_list_t *pl, const uint8_t num_entries);
#endif // OXEN_PLAYER_H
diff --git a/src/ui.c b/src/ui.c
index 990e235..e081186 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -24,6 +24,8 @@ static WINDOW *w_current_state;
static WINDOW *w_messages;
static WINDOW *w_hand_cards;
+static WINDOW *w_final_scores;
+
static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const bool highlight, const card c)
{
assert(w != NULL);
@@ -334,6 +336,62 @@ void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint
wnoutrefresh(w_hand_cards);
}
+/**
+ * Displays the final scores window and highlights the player.
+*/
+void ui_display_wnd_final_scores(const player_list_t *pl, const uint8_t num_players, const uint8_t highlighted_player)
+{
+ uint8_t row = 4;
+ uint8_t place = 1;
+
+ clear();
+ refresh();
+
+ wattron(w_final_scores, A_BOLD);
+ mvwprintw(w_final_scores, 1, 7, "- Final standings -");
+ mvwprintw(w_final_scores, 3, 2, "Pos: Player: Score:");
+ wattroff(w_final_scores, A_BOLD);
+
+ for (int i = 0; i < num_players; i++)
+ {
+ const player_list_entry_t *ple = &pl->players[i];
+
+ if (0 == ple->player_id) // Skip empty player list entries
+ continue;
+
+ // If the previous player has the same score, we have the same place as he does
+ if (i > 0 && pl->players[i-1].score == ple->score)
+ place = place - 1;
+
+ // Reward the glorious winners with an outstanding output of their scores
+ if (1 == place)
+ wattron(w_final_scores, A_BOLD);
+
+ if (ple->player_id == highlighted_player || 1 == place) // Highlight the players score
+ {
+ wattron(w_final_scores, COLOR_PAIR(CP_YELLOW_ON_BLACK));
+ mvwprintw(w_final_scores, row, 2, "%2d.", place);
+ mvwprintw(w_final_scores, row, 7, "%-s", ple->player_name);
+ mvwprintw(w_final_scores, row++, 25, "%3d", ple->score);
+ wattroff(w_final_scores, COLOR_PAIR(CP_YELLOW_ON_BLACK));
+ }
+ else
+ {
+ mvwprintw(w_final_scores, row, 2, "%2d.", place);
+ mvwprintw(w_final_scores, row, 7, "%-s", ple->player_name);
+ mvwprintw(w_final_scores, row++, 25, "%3d", ple->score);
+ }
+
+ if (1 == place)
+ wattroff(w_final_scores, A_BOLD);
+
+ place++;
+ }
+
+ wrefresh(w_final_scores);
+ while (KEY_RETURN != wgetch(w_final_scores));
+}
+
uint8_t ui_choose_card(hand_t *h)
{
assert(h != NULL);
@@ -480,6 +538,9 @@ void ui_init(void)
w_messages = newwin(2, 39, 7, 24);
w_hand_cards = newwin(11, 39, 10, 24);
+ w_final_scores = newwin(15, 32, 2, 15);
+ box(w_final_scores, 0, 0);
+
// Set input settings for windows
keypad(w_table_cards, true); // We get F1, F2 etc..
keypad(w_hand_cards, true); // We get F1, F2 etc..
@@ -499,5 +560,6 @@ void ui_fini(void)
delwin(w_current_state);
delwin(w_messages);
delwin(w_hand_cards);
+ delwin(w_final_scores);
endwin(); // End curses mode
}
diff --git a/src/ui.h b/src/ui.h
index 189b818..1b88672 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -12,6 +12,7 @@ void ui_display_wnd_stack_points(const table_stacks_t *ts, const bool highlight,
void ui_display_wnd_current_state(const player_list_t *pl, const uint8_t num_players, const bool highlight, const uint8_t highlighted_player, const uint32_t score);
void ui_display_wnd_messages(const char *message, const bool highlight);
void ui_display_wnd_hand_cards(const hand_t *h, const bool highlight, const uint8_t highlighted_card);
+void ui_display_wnd_final_scores(const player_list_t *pl, const uint8_t num_players, const uint8_t highlighted_player);
uint8_t ui_choose_card(hand_t *h);
uint8_t ui_choose_stack(const table_stacks_t *ts);
void ui_update(void);