summaryrefslogtreecommitdiff
path: root/src/server_game_states.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server_game_states.c')
-rw-r--r--src/server_game_states.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/server_game_states.c b/src/server_game_states.c
index f3089fc..4ec7154 100644
--- a/src/server_game_states.c
+++ b/src/server_game_states.c
@@ -28,7 +28,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
#include "data_store.h"
+#include "ui.h"
/**
* Game state handler. If it is the first round, the server takes cards from the main stack and places them onto the table, as table stacks. The server then sends the table stacks to all players. After this, the hands for the players will be drawn from the main stack and sent to the players. On returning from the function, a state transition occurs.
@@ -49,6 +51,12 @@ game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, con
d->table_stacks.stacks[2].cards[0] = main_stack_remove_card(m);
d->table_stacks.stacks[3].cards[0] = main_stack_remove_card(m);
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
for(int i = 0; i < d->player_list.count; i++)
{
net_send(client_socks->sockets[i], msg_type_initial_stacks, NULL);
@@ -90,6 +98,11 @@ game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks)
{
data_store_t *d = data_store();
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Waiting for the players to pick their cards", false); // The two spaces between 'their' and 'cards' are intentionally and used for poor man's word wrap
+ ui_update();
+#endif // OXEN_DGLSERVER
+
// Receive open cards from clients
for(int i = 0; i < d->player_list.count; i++)
{
@@ -134,15 +147,32 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
card c = d->player_list.players[i].open_card;
uint8_t stack_idx = get_stack_idx_for_card(&d->table_stacks, c);
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Placing cards ...", false);
+ ui_display_wnd_current_state(&d->player_list, d->player_list.count, true, i, -1);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
if(stack_idx >= NUM_TABLE_STACKS) // card does not fit on any stack
{
int cur_sock = socket_for_player_id(client_socks, d->player_list.players[i].player_id);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Waiting for player to choose stack", false);
+ ui_update();
+#endif // OXEN_DGLSERVER
+
net_recv(cur_sock, msg_type_selected_stack_c);
for(int j=0; j<client_socks->count; j++) // send received stack to all clients (including the one who sent it)
net_send(client_socks->sockets[j], msg_type_selected_stack_s, NULL);
d->player_list.players[i].score += card_stack_get_points(&d->table_stacks.stacks[d->stack_index]);
card_stack_replace(&d->table_stacks.stacks[d->stack_index], c);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+#endif // OXEN_DGLSERVER
}
else // card fits on a stack -> place it
{
@@ -153,17 +183,22 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
card_stack_replace(cs, c);
}
else
- {
- // put open card on top of stack
- for(int j=0; j<MAX_CARD_STACK_SIZE; j++)
- {
- if(cs->cards[j] != 0)
- continue;
- cs->cards[j] = c;
- break;
- }
- }
+ card_stack_push(cs, c);
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_table_cards(&d->table_stacks, false, 0);
+ ui_display_wnd_stack_points(&d->table_stacks, false, 0);
+#endif // OXEN_DGLSERVER
}
+
+#ifdef OXEN_DGLSERVER
+ ui_display_wnd_messages("Placing cards ...", false); // may have been overwritten by "Waiting .. stack" message. Rewrite it.
+ ui_update();
+
+ // Wait between player turns, but not after the last one
+ if (i != d->player_list.count - 1)
+ sleep(2);
+#endif // OXEN_DGLSERVER
}
if(hand_count_cards(&d->hand) > 0) // still cards in hand?
@@ -198,4 +233,12 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma
*/
void state_server_game_finished(void)
{
+#ifdef OXEN_DGLSERVER
+ 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();
+ sleep(5);
+#endif // OXEN_DGLSERVER
}