From 9780e8c24b45cfb47085d77ae64ba1f91d31419e Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Tue, 25 Jan 2011 15:50:27 +0100 Subject: Implemented card_stack_push(). Renamed card_stack_clear() to card_stack_replace() and card_stack_upper_card() to card_stack_top(). Added documentation. --- src/card_stack.c | 40 +++++++++++++++++++++++++++++++++++----- src/card_stack.h | 5 +++-- src/client_game_states.c | 15 +++------------ src/table_stacks.c | 2 +- 4 files changed, 42 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/card_stack.c b/src/card_stack.c index 13b14dd..f3bd217 100644 --- a/src/card_stack.c +++ b/src/card_stack.c @@ -2,6 +2,10 @@ #include #include +/** + * Calculates the points of a card stack. This will be the sum of the points of all cards contained in the card stack. + * @param[in] cs The card stack fir which the points will be calculated +*/ uint32_t card_stack_get_points(const card_stack_t *cs) { assert(cs != NULL); @@ -17,11 +21,15 @@ uint32_t card_stack_get_points(const card_stack_t *cs) return points; } -const card card_stack_upper_card(const card_stack_t *cs) +/** + * Determines the uppermost card on a card stack. The card will not be removed from the stack. + * @param[in] cs The card stack from which the uppermost card will be retrieved +*/ +const card card_stack_top(const card_stack_t *cs) { assert(cs != NULL); - for(int i=0; icards[MAX_CARD_STACK_SIZE-1-i]; if(cur != 0) @@ -31,13 +39,35 @@ const card card_stack_upper_card(const card_stack_t *cs) return 0; } -void card_stack_clear(card_stack_t *cs, const card new_card) +/** + * Places a card on top of a card stack. + * @param[in] cs The card stack to place the card on + * @param[in] c The card to place +*/ +void card_stack_push(card_stack_t *cs, const card c) { assert(cs != NULL); - for(int i=0; icards[i] != 0) + continue; + cs->cards[i] = c; + break; + } +} + +/** + * Replaces a card stack with a single card. All cards within the card stack will be removed adn the first card will be set to a given card. + * @param[in] cs The card stack to replace + * @param[in] new_card The new first card +*/ +void card_stack_replace(card_stack_t *cs, const card new_card) +{ + assert(cs != NULL); + + for(int i = 0; i < MAX_CARD_STACK_SIZE; i++) cs->cards[i] = 0; cs->cards[0] = new_card; } - diff --git a/src/card_stack.h b/src/card_stack.h index 61d2bf2..7e1d976 100644 --- a/src/card_stack.h +++ b/src/card_stack.h @@ -12,7 +12,8 @@ typedef struct } card_stack_t; uint32_t card_stack_get_points(const card_stack_t *cs); -const card card_stack_upper_card(const card_stack_t *cs); -void card_stack_clear(card_stack_t *cs, const card new_card); +const card card_stack_top(const card_stack_t *cs); +void card_stack_push(card_stack_t *cs, const card c); +void card_stack_replace(card_stack_t *cs, const card new_card); #endif // OXEN_CARD_STACK_H diff --git a/src/client_game_states.c b/src/client_game_states.c index 142693e..2b11d51 100644 --- a/src/client_game_states.c +++ b/src/client_game_states.c @@ -80,7 +80,7 @@ game_state_t state_client_play_cards(const int sock, const uint8_t round) 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_clear(&ds->table_stacks.stacks[ds->stack_index], c); + card_stack_replace(&ds->table_stacks.stacks[ds->stack_index], c); } else // card fits on a stack -> place it { @@ -88,19 +88,10 @@ game_state_t state_client_play_cards(const int sock, const uint8_t round) 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_clear(cs, c); + card_stack_replace(cs, c); } else - { - // put open card on top of stack - for(int j=0; jcards[j] != 0) - continue; - cs->cards[j] = c; - break; - } - } + card_stack_push(cs, c); } } #if 0 diff --git a/src/table_stacks.c b/src/table_stacks.c index 9a32977..7f76edd 100644 --- a/src/table_stacks.c +++ b/src/table_stacks.c @@ -14,7 +14,7 @@ const uint8_t get_stack_idx_for_card(const table_stacks_t* stack_list, const car for(int i=0; istacks[i]); + card stackcard = card_stack_top(&stack_list->stacks[i]); uint8_t new_diff = c - stackcard; assert(new_diff != 0); -- cgit v1.2.3 From 80eead4f5ab998a0e6b678f8c1c0fcd969d6b07c Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Tue, 25 Jan 2011 16:08:46 +0100 Subject: Added documentation. --- src/net/server.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/net/server.c b/src/net/server.c index 7e9a111..54601ed 100644 --- a/src/net/server.c +++ b/src/net/server.c @@ -10,7 +10,7 @@ #include "../data_store.h" /** - * Server side function; start server on specified port + * Starts the server. The server will listen on a specified port. * @param[in] port Port on which server should listen * @return Listening socket */ @@ -74,7 +74,7 @@ int server_start(const char* port) } /** - * Server side function; accepts connections from clients + * Waits for and accepts connections from clients. Each client connection is represented by a socket that will be stored in a list for further communication. * @param[in] serversock Socket on which server is listening * @param[out] client_socks Socket list in which to store open client connections * @param[in] count Number of clients that should connect @@ -103,9 +103,9 @@ void server_get_players(int serversock, socket_list_t* client_socks, const uint8 } /** - * Server side function; receive hello message from client and read username - * @param[in] sock Socket to use - * @return Username of client + * Parses hello message from client and store username in the global data store. + * @param[in] msg The message to parse + * @return true */ bool server_parse_hello(const msg_t *m) { @@ -126,6 +126,11 @@ bool server_parse_hello(const msg_t *m) return true; } +/** + * Parses open card message from client and stores the selected card in the global data store. + * @param[in] msg The message to parse + * @return true + */ bool server_parse_selected_card(const msg_t *m) { assert(m != NULL); @@ -137,6 +142,11 @@ bool server_parse_selected_card(const msg_t *m) return true; } +/** + * Parses selected stack message from client and stores the stack index in the global data store. + * @param[in] msg The message to parse + * @return true + */ bool server_parse_selected_stack(const msg_t *m) { assert(m != NULL); @@ -150,6 +160,10 @@ bool server_parse_selected_stack(const msg_t *m) return true; } +/** + * Prepares start game message. All player IDs, player names and name lengths will be saved in the message payload. + * @param[out] msg A preallocated message object to store header and payload information + */ void server_prep_start_game(msg_t *m) { uint16_t pos = 0; -- cgit v1.2.3