#include "game_states.h" #include "net/comm.h" #include "ui.h" #include "data_store.h" game_state_t state_client_wait_for_hand_cards(const int sock, const uint8_t round) { data_store_t *d = data_store(); ui_display_wnd_messages("Waiting for hand cards from server"); if(round == 1) { // Receive and display table stacks net_recv(sock, msg_type_initial_stacks); ui_display_wnd_table_cards(&d->table_stacks, false, 0); ui_display_wnd_stack_points(&d->table_stacks, false, 0); } // Wait for hand cards from server and display them net_recv(sock, msg_type_deal_hand); ui_display_wnd_hand_cards(&d->hand, false, 0); return STATE_CLIENT_SELECT_OPEN_CARD; } game_state_t state_client_select_open_card(const int sock) { data_store_t *d = data_store(); uint8_t open_card_idx; ui_display_wnd_messages("Please choose the card you want to play"); // Select open card open_card_idx = ui_choose_card(&d->hand); d->selected_card = d->hand.cards[open_card_idx]; // Send open card to server net_send(sock, msg_type_selected_card, NULL); // Remove picked open card from hand hand_remove_card(&d->hand, open_card_idx); ui_display_wnd_hand_cards(&d->hand, false, 0); return STATE_CLIENT_WAIT_FOR_OPEN_CARDS; } game_state_t state_client_wait_for_open_cards(const int sock) { data_store_t *d = data_store(); ui_display_wnd_messages("Waiting for the other players to pick their cards"); net_recv(sock, msg_type_selected_card_all); player_list_sort_by_open_card(&d->player_list, d->player_list.count); // sort in ascending order ui_display_wnd_current_state(&d->player_list, d->player_list.count, true, 0, 0); // TODO fix parameters return STATE_CLIENT_PLAY_CARDS; } game_state_t state_client_play_cards(const int sock) { data_store_t *ds = data_store(); for(int i=0; iplayer_list.count; i++) { card c = ds->player_list.players[i].open_card; uint8_t stack_idx = get_stack_idx_for_card(&ds->table_stacks, c); if(stack_idx >= NUM_TABLE_STACKS) // card does not fit on any stack { if(ds->player_list.players[i].player_id == ds->own_player_id) // our turn to select stack { ui_display_wnd_messages("Please choose a stack"); ds->stack_index = ui_choose_stack(&ds->table_stacks); net_send(sock, msg_type_selected_stack_c, NULL); } ui_display_wnd_messages("Waiting for chosen stack"); net_recv(sock, msg_type_selected_stack_s); ds->player_list.players[i].score += card_stack_get_points(&ds->table_stacks.stacks[ds->stack_index]); card_stack_replace(&ds->table_stacks.stacks[ds->stack_index], c); ui_display_wnd_table_cards(&ds->table_stacks, false, 0); ui_display_wnd_stack_points(&ds->table_stacks, false, 0); } else // card fits on a stack -> place it { card_stack_t* cs = &ds->table_stacks.stacks[stack_idx]; if(cs->cards[MAX_CARD_STACK_SIZE-1] != 0) // stack is full { ds->player_list.players[i].score += card_stack_get_points(cs); card_stack_replace(cs, c); } else card_stack_push(cs, c); ui_display_wnd_table_cards(&ds->table_stacks, false, 0); ui_display_wnd_stack_points(&ds->table_stacks, false, 0); } } if(hand_count_cards(&ds->hand) > 0) // still cards in hand? { return STATE_CLIENT_SELECT_OPEN_CARD; } else { net_recv(sock, msg_type_next_action); if(!ds->game_finished) // no more cards -> server will deal return STATE_CLIENT_WAIT_FOR_HAND_CARDS; else return STATE_CLIENT_GAME_FINISHED; } assert(false); return 1337; }