diff options
| author | Mario Kilies <MarioKilies@GMX.net> | 2011-01-29 17:57:16 +0100 |
|---|---|---|
| committer | Mario Kilies <MarioKilies@GMX.net> | 2011-01-29 17:57:16 +0100 |
| commit | ab80fa342031a548b549e4581cb946982b433c3a (patch) | |
| tree | 7d2afc0e65eabbfa8915e82e1a2d76a654348483 | |
| parent | 9e7d99dfbbe41e4b97f8d8728fe44cdcc7a0ad28 (diff) | |
Added state_server_game_finished(). Added documentation for server_game_states.c.
| -rw-r--r-- | src/game.c | 1 | ||||
| -rw-r--r-- | src/game_states.h | 1 | ||||
| -rw-r--r-- | src/server_game_states.c | 26 |
3 files changed, 28 insertions, 0 deletions
@@ -94,6 +94,7 @@ static void main_loop_server(socket_list_t* client_socks) case STATE_SERVER_GAME_FINISHED: // Game finished. No further state transition here + state_server_game_finished(); running = false; break; default: diff --git a/src/game_states.h b/src/game_states.h index b7df1f5..bc99108 100644 --- a/src/game_states.h +++ b/src/game_states.h @@ -29,5 +29,6 @@ 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); game_state_t state_server_play_cards(const socket_list_t *client_socks, const main_stack_t *m); +void state_server_game_finished(void); #endif // OXEN_GAME_STATES_H diff --git a/src/server_game_states.c b/src/server_game_states.c index 1fafb8c..c605e48 100644 --- a/src/server_game_states.c +++ b/src/server_game_states.c @@ -4,6 +4,12 @@ #include <stdio.h> #include "data_store.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. + * @param[in] client_socks The client sockets used for communication + * @param[in] round The current round of the game + * @return STATE_SERVER_WAIT_FOR_OPEN_CARDS The next state after dealing hand cards +*/ game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, const uint8_t round, main_stack_t *m) { data_store_t *d = data_store(); @@ -48,6 +54,11 @@ game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, con return STATE_SERVER_WAIT_FOR_OPEN_CARDS; } +/** + * Game state handler. In this state, the server waits for all clients to choose their open card. After receiving all open cards, the list of all open cards will be propagated to all players. On returning from the function, a state transition occurs. + * @param[in] client_socks The client sockets used for communication + * @return STATE_SERVER_PLAY_CARDS The next state after waiting for all open cards +*/ game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks) { data_store_t *d = data_store(); @@ -78,6 +89,14 @@ game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks) return STATE_SERVER_PLAY_CARDS; } +/** + * Game state handler. In this state, the server tries to play all open cards. If a player's card is smaller than all the cards on the stacks, the player has to choose a stack. Receive the player's chosen stack, replace it with his open card and increment the player's score. If the player's card fits on a stack, but the stack is already full, then replace the stack with the card, and add the stack points to the player's points. + * If the players still have hand cards, then wait for chosen open cards from players. If the players do not have anymore hand cards and the mainstack has enough cards to deal every player at least one card, then deal new hand cards. Otherwise the game has finished. + * @param[in] sock The server socket that is read/written to + * @return STATE_SERVER_WAIT_FOR_OPEN_CARDS The next state, if the players still have hand cards + * @return STATE_SERVER_DEAL_HAND_CARDS The next state, if the main stack has at least one card for each player left. The server will then deal those cards + * @return STATE_SERVER_GAME_FINISHED The next state, if the main stack is empty +*/ game_state_t state_server_play_cards(const socket_list_t *client_socks, const main_stack_t *m) { data_store_t *d = data_store(); @@ -145,3 +164,10 @@ game_state_t state_server_play_cards(const socket_list_t *client_socks, const ma assert(false); return 1337; } + +/** + * Game state handler. Will be called if the game has finished. As the game has finished, no state transition takes place before returning from this function. +*/ +void state_server_game_finished(void) +{ +} |
