back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-08-16 18:10:11 +0300
committerscratko <m@scratko.xyz>2024-08-16 18:10:11 +0300
commiteb90648bdad1443c9cfc72e903a93642e10a0ab7 (patch)
treedc567a9aa834bb0d5f3429e8a38910990d75e4eb /client
parent880b8be2c28d761505b2eecc1386919d5add6f2f (diff)
downloaddurak-eb90648bdad1443c9cfc72e903a93642e10a0ab7.tar.gz
durak-eb90648bdad1443c9cfc72e903a93642e10a0ab7.tar.bz2
durak-eb90648bdad1443c9cfc72e903a93642e10a0ab7.zip
Global fixes v2.0
Added spectator mode. Added screen of game result. Added definition of durak. If not all players can replenish their decks, they take cards one at a time in turn.
Diffstat (limited to 'client')
-rw-r--r--client/client.c20
-rw-r--r--client/client.h13
-rw-r--r--client/data_decryption.c16
-rw-r--r--client/data_decryption.h4
-rw-r--r--client/printing_game_frames.c32
-rw-r--r--client/printing_game_frames.h3
6 files changed, 81 insertions, 7 deletions
diff --git a/client/client.c b/client/client.c
index 4abcf7d..a5b3daf 100644
--- a/client/client.c
+++ b/client/client.c
@@ -54,13 +54,19 @@ static void get_data_from_server(struct client *cl, fd_set *readfds)
decrypt_set_position_whose_turn(cl, end_p+1, &end_p);
break;
case defense_expectation:
+ case spectator:
decrypt_set_base_info(cl, end_p+1, &end_p);
decrypt_set_position_whose_turn(cl, end_p+1, &end_p);
- decrypt_set_card_queue(cl, end_p+1);
+ decrypt_set_card_queue(cl, end_p+1, &end_p);
+ if(cl->state == spectator)
+ decrypt_set_spectator_mode(cl, end_p+1);
break;
case card_acceptance_status:
decrypt_set_card_acceptance_status(cl, end_p+1);
break;
+ case result:
+ decrypt_set_durak_position(cl, end_p+1);
+ break;
/* no data to extract */
case tossing_limit_status:
default:
@@ -102,6 +108,7 @@ static void prepare_tips_for_client(struct client *cl)
static void change_client_frame(struct client *cl)
{
if(cl->display_new_frame) {
+ pgf_new_frame();
switch(cl->state) {
case first_player:
pgf_first_player();
@@ -121,6 +128,10 @@ static void change_client_frame(struct client *cl)
pgf_select_idle_mode_message(cl->state);
}
break;
+ case spectator:
+ pgf_table(cl);
+ pgf_spectator_mode(cl->sp_mode);
+ break;
case attack:
case defense:
case tossing:
@@ -133,7 +144,10 @@ static void change_client_frame(struct client *cl)
case tossing_limit_status:
pgf_tossing_limit_status();
break;
- default:
+ case result:
+ pgf_game_result(cl->durak_position);
+ break;
+ case none:
{}
}
cl->display_new_frame = 0;
@@ -229,6 +243,8 @@ static void init_client(struct client *cl)
cl->display_new_frame = 0;
cl->all_input_cards_accepted = 0;
cl->data_left_in_buffer = 0;
+ cl->sp_mode = spectator_table;
+ cl->durak_position = 0;
}
/*
diff --git a/client/client.h b/client/client.h
index 9bdd8cc..1ff8f82 100644
--- a/client/client.h
+++ b/client/client.h
@@ -23,7 +23,16 @@ enum client_states {
defense,
tossing,
card_acceptance_status,
- tossing_limit_status
+ tossing_limit_status,
+ spectator,
+ result
+};
+
+enum spectator_mode {
+ spectator_attack,
+ spectator_defense,
+ spectator_tossing,
+ spectator_table
};
struct cards_on_table {
@@ -67,6 +76,8 @@ struct client {
int display_new_frame;
int all_input_cards_accepted;
int data_left_in_buffer;
+ enum spectator_mode sp_mode;
+ int durak_position;
};
#endif
diff --git a/client/data_decryption.c b/client/data_decryption.c
index b445454..1054c45 100644
--- a/client/data_decryption.c
+++ b/client/data_decryption.c
@@ -126,14 +126,15 @@ void decrypt_set_position_whose_turn(struct client *cl, char *start_p,
cl->position_whose_turn = decrypt_get_number(start_p, end_p);
}
-void decrypt_set_card_queue(struct client *cl, char *start_p)
+void decrypt_set_card_queue(struct client *cl, char *start_p, char **end_p)
{
int i, j;
- for(i = 0, j = 0; *start_p != '\n'; ++start_p) {
+ for(i = 0, j = 0; *start_p != ':' && *start_p != '\n'; ++start_p) {
/* empty queue */
if(*start_p == '=') {
i = -1;
+ ++start_p;
break;
}
/* delimiter '\' */
@@ -150,6 +151,7 @@ void decrypt_set_card_queue(struct client *cl, char *start_p)
if(i != -1)
cl->cq.card_arr[i][j] = '\0';
cl->cq.card_arr_idx = i;
+ *end_p = start_p;
}
void decrypt_set_card_acceptance_status(struct client *cl, char *start_p)
@@ -167,3 +169,13 @@ void decrypt_set_card_acceptance_status(struct client *cl, char *start_p)
if(!strcmp(tmp_buffer, "not all"))
cl->all_input_cards_accepted = 0;
}
+
+void decrypt_set_spectator_mode(struct client *cl, char *start_p)
+{
+ cl->sp_mode = (enum spectator_mode) decrypt_get_number(start_p, NULL);
+}
+
+void decrypt_set_durak_position(struct client *cl, char *start_p)
+{
+ cl->durak_position = decrypt_get_number(start_p, NULL);
+}
diff --git a/client/data_decryption.h b/client/data_decryption.h
index b53e53f..08772fe 100644
--- a/client/data_decryption.h
+++ b/client/data_decryption.h
@@ -8,7 +8,9 @@ int decrypt_get_number(char *start_p, char **end_p);
void decrypt_set_base_info(struct client *cl, char *start_p, char **end_p);
void decrypt_set_position_whose_turn(struct client *cl, char *start_p,
char **end_p);
-void decrypt_set_card_queue(struct client *cl, char *start_p);
+void decrypt_set_card_queue(struct client *cl, char *start_p, char **end_p);
void decrypt_set_card_acceptance_status(struct client *cl, char *start_p);
+void decrypt_set_spectator_mode(struct client *cl, char *start_p);
+void decrypt_set_durak_position(struct client *cl, char *start_p);
#endif
diff --git a/client/printing_game_frames.c b/client/printing_game_frames.c
index f75cec5..5c7deac 100644
--- a/client/printing_game_frames.c
+++ b/client/printing_game_frames.c
@@ -3,6 +3,14 @@
#include <stdio.h>
+void pgf_new_frame()
+{
+ int i;
+
+ for(i = 0; i < 25; ++i)
+ printf("\n");
+}
+
void pgf_first_player()
{
printf("=======================================\n"
@@ -54,7 +62,8 @@ void pgf_table(struct client *cl)
printf("\n");
deck = deck->next;
}
- printf("\n");
+ if(cl->deck)
+ printf("\n");
}
void pgf_suggestions(struct client *cl)
@@ -104,3 +113,24 @@ void pgf_tossing_limit_status()
printf("the cards were not accepted.\n"
"The other players have already tossed cards.\n");
}
+
+void pgf_spectator_mode(enum spectator_mode sp_mode)
+{
+ printf("spectator mode\n");
+ if(sp_mode == spectator_attack)
+ printf("attacker makes a move\n");
+ else if(sp_mode == spectator_defense)
+ printf("defender make a move\n");
+ else if(sp_mode == spectator_tossing)
+ printf("players toss in extra cards\n");
+ else
+ printf("round result\n");
+}
+
+void pgf_game_result(int durak_position)
+{
+ printf("===============================\n"
+ " END OF GAME\n"
+ "player under number %u is durak\n"
+ "===============================\n", durak_position);
+}
diff --git a/client/printing_game_frames.h b/client/printing_game_frames.h
index e3c844a..cd72932 100644
--- a/client/printing_game_frames.h
+++ b/client/printing_game_frames.h
@@ -10,5 +10,8 @@ void pgf_suggestions(struct client *cl);
void pgf_select_idle_mode_message(enum client_states state);
void pgf_card_acceptance_status(int all_input_cards_accepted);
void pgf_tossing_limit_status();
+void pgf_spectator_mode(enum spectator_mode sp_mode);
+void pgf_game_result(int durak_position);
+void pgf_new_frame();
#endif