From 49a31a58e1b77ed0d88c0271247d4f707cf8b641 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Tue, 25 Jan 2011 14:36:47 +0100 Subject: implement part of state_client_play_cards(); added new message type: hello reply from server which notifies clients of their player-ids --- src/client_game_states.c | 58 +++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'src/client_game_states.c') diff --git a/src/client_game_states.c b/src/client_game_states.c index 58e55db..2682d67 100644 --- a/src/client_game_states.c +++ b/src/client_game_states.c @@ -56,38 +56,49 @@ game_state_t state_client_wait_for_open_cards(const int sock) game_state_t state_client_play_cards(const int sock, const uint8_t round) { -#if 0 - data_store_t *d = data_store(); - uint8_t stack_idx; + data_store_t *ds = data_store(); - foreach(open_card) + for(int i=0; iplayer_list.count; i++) { - play_lowest_open_card + 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 { - determine_stack_for_open_card + uint32_t stack_points; + + if(ds->player_list.players[i].player_id == ds->own_player_id) // our turn to select stack { - if (stack_has_to_be_picked) - { - if (we_have_to_pick) - { - pick_stack(); - send_stack_to_server(); - } - else // another client has to pick - { - receive_stack(); - } - - clear_stack(stack_id); - } + ds->stack_index = ui_choose_stack(&ds->table_stacks); + net_send(sock, msg_type_selected_stack_c, NULL); } - place_card() + + net_recv(sock, msg_type_selected_stack_s); + stack_points = card_stack_get_points(&ds->table_stacks.stacks[ds->stack_index]); + card_stack_clear(&ds->table_stacks.stacks[ds->stack_index], c); + } + 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 { - if(count_stack_cards == 6) - clear_stack(stack_id); + uint32_t stack_points = card_stack_get_points(cs); + card_stack_clear(cs, c); + } + else + { + // put open card on top of stack + for(int j=0; jcards[j] != 0) + continue; + cs->cards[j] = c; + break; + } } } } +#if 0 if (we_have_hand_cards) { return STATE_CLIENT_SELECT_OPEN_CARD; @@ -104,5 +115,6 @@ game_state_t state_client_play_cards(const int sock, const uint8_t round) return STATE_CLIENT_GAME_FINISHED; } #endif + return 1337; } -- cgit v1.2.3