From 9970a2275a56d7835ba0c12a8586dc25cf7ec1cf Mon Sep 17 00:00:00 2001 From: scratko Date: Sun, 18 Aug 2024 01:33:08 +0300 Subject: Global fixes v4.0 Removed unnecessary comments. Added resource cleanup for client and server. Changed queue display. Added player indicator. It's possible to quit the game while typing or waiting for a connection. Fixed a bug with determining the limit of card tossing. --- client/printing_game_frames.c | 45 +++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'client/printing_game_frames.c') diff --git a/client/printing_game_frames.c b/client/printing_game_frames.c index bda1208..6b2131a 100644 --- a/client/printing_game_frames.c +++ b/client/printing_game_frames.c @@ -2,6 +2,7 @@ #include "card_stack.h" #include +#include void pgf_new_frame() { @@ -34,29 +35,39 @@ void pgf_first_player() printf("=======================================\n" " You're the first player\n" "Waiting for other players to connect...\n" + " Press q to exit\n" "=======================================\n"); } void pgf_confirmation_waiting(int total_players) { printf("=======================================\n" - " To start game press key \n" - " Connected players: %u/8 \n" + " To start game press key\n" + " Connected players: %u/8\n" + " Press q to exit\n" "=======================================\n", total_players); } +static int move_indication_condition(const struct client *cl, + int current_player) +{ + return + current_player == cl->position_whose_turn && + (cl->state == attack_expectation || cl->state == defense_expectation || + cl->state == attack || cl->state == defense || + (cl->state == spectator && (cl->sp_mode == spectator_attack || + cl->sp_mode == spectator_defense))); +} + void pgf_table(struct client *cl) { struct card_stack_item *deck = NULL; int i; for(i = 0; i <= cl->cc.number_arr_idx; ++i) - /* printing who will move */ - if(cl->state == attack_expectation || cl->state == defense_expectation) - printf("<%c%u > ", cl->position_whose_turn-1 == i ? '*' : ' ', - cl->cc.number_arr[i]); - else - printf("< %u > ", cl->cc.number_arr[i]); + printf("<%s %u %c> ", cl->player_position == i+1 ? "YOU" : " ", + cl->cc.number_arr[i], move_indication_condition(cl, i+1) ? + '*' : ' '); printf(" %s [ %u ]", cl->trump_card, cl->total_cards_left); printf("\n\n\n"); /* ================= cards on table ================ */ @@ -64,7 +75,7 @@ void pgf_table(struct client *cl) printf(" %s %s %s\n", cl->cot.card_arr[i], cl->cot.card_arr[i+1], cl->cot.card_arr[i+2]); /* for the defender, the cards in the queue are hidden */ - if(cl->state == defense_expectation) + if(cl->state == defense_expectation || cl->state == spectator) for(i = 0; i <= cl->cq.card_arr_idx; ++i) printf(" %s \\ -\n", cl->cq.card_arr[i]); if(cl->cot.card_arr_idx != -1) @@ -88,6 +99,7 @@ void pgf_suggestions(struct client *cl) { struct card_stack_item *deck = NULL; + printf("qq - exit the game\n"); if(cl->state == attack || cl->state == tossing) printf("you can specify more than one card\n"); deck = cl->deck; @@ -152,7 +164,20 @@ void pgf_game_result(int durak_position) "=======================================\n", durak_position); } +static void clear_input() +{ + int key; + + while((key = getchar()) != '\n') + {} +} + void pgf_disconnect() { - printf("Server connection disconnected\n"); + char key; + + printf("Server connection disconnected\n" + "Press to close program\n"); + while((key = getchar()) != '\n') + clear_input(); } -- cgit v1.2.3