back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/client/printing_game_frames.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-08-18 01:33:08 +0300
committerscratko <m@scratko.xyz>2024-08-18 01:33:08 +0300
commit9970a2275a56d7835ba0c12a8586dc25cf7ec1cf (patch)
tree914b9353b2df1ba9dec5481fa3e7e6a8462dea5d /client/printing_game_frames.c
parent4b2fdc91d42a438193d15840e10851c3847fbe80 (diff)
downloaddurak-9970a2275a56d7835ba0c12a8586dc25cf7ec1cf.tar.gz
durak-9970a2275a56d7835ba0c12a8586dc25cf7ec1cf.tar.bz2
durak-9970a2275a56d7835ba0c12a8586dc25cf7ec1cf.zip
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.
Diffstat (limited to 'client/printing_game_frames.c')
-rw-r--r--client/printing_game_frames.c45
1 files changed, 35 insertions, 10 deletions
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 <stdio.h>
+#include <unistd.h>
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 <Enter> to exit\n"
"=======================================\n");
}
void pgf_confirmation_waiting(int total_players)
{
printf("=======================================\n"
- " To start game press <Enter> key \n"
- " Connected players: %u/8 \n"
+ " To start game press <Enter> key\n"
+ " Connected players: %u/8\n"
+ " Press q <Enter> 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 <Enter> to close program\n");
+ while((key = getchar()) != '\n')
+ clear_input();
}