back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/windows_client/printing_game_frames.c
diff options
context:
space:
mode:
Diffstat (limited to 'windows_client/printing_game_frames.c')
-rw-r--r--windows_client/printing_game_frames.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/windows_client/printing_game_frames.c b/windows_client/printing_game_frames.c
new file mode 100644
index 0000000..6b2131a
--- /dev/null
+++ b/windows_client/printing_game_frames.c
@@ -0,0 +1,183 @@
+#include "printing_game_frames.h"
+#include "card_stack.h"
+
+#include <stdio.h>
+#include <unistd.h>
+
+void pgf_new_frame()
+{
+ int i;
+
+ for(i = 0; i < 25; ++i)
+ printf("\n");
+}
+
+void pgf_welcome()
+{
+ printf("======================================================\n"
+ " Welcome!\n"
+ "You're playing siege durak/Podkidnoy (Throw-in) durak\n\n"
+ "If you have any questions, you can contact by email to\n"
+ " m@scratko.xyz\n"
+ "======================================================\n");
+}
+
+void pgf_connection(int status)
+{
+ if(status)
+ printf("Connection to the server has been successfully established\n");
+ else
+ printf("Sorry, failed to connect to the server\n");
+}
+
+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"
+ " 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)
+ 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 ================ */
+ for(i = 0; i <= cl->cot.card_arr_idx; i += 3)
+ 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 || 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)
+ printf("\n\n");
+ /* ================ player's deck ================ */
+ deck = cl->deck;
+ i = 0;
+ while(deck) {
+ printf("%c: %s ", deck->tip, deck->str);
+ ++i;
+ /* line break every 6 cards */
+ if(!(i % 6))
+ printf("\n");
+ deck = deck->next;
+ }
+ if(cl->deck)
+ printf("\n");
+}
+
+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;
+ while(deck) {
+ if(deck->is_usable)
+ printf("%c", deck->tip);
+ deck = deck->next;
+ }
+ printf(" > ");
+ fflush(stdout);
+}
+
+void pgf_select_idle_mode_message(enum client_states state)
+{
+ switch(state) {
+ case attack_expectation:
+ printf("waiting for the attacker's turn\n");
+ break;
+ case defense_expectation:
+ printf("waiting for the defender's turn\n");
+ break;
+ case tossing_expectation:
+ printf("waiting for other players to toss cards\n");
+ break;
+ default:
+ {}
+ }
+}
+
+void pgf_card_acceptance_status(int all_input_cards_accepted)
+{
+ if(all_input_cards_accepted)
+ printf("all cards accepted\n");
+ else
+ printf("not all cards were accepted\n");
+}
+
+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 number %u is durak\n"
+ "=======================================\n", durak_position);
+}
+
+static void clear_input()
+{
+ int key;
+
+ while((key = getchar()) != '\n')
+ {}
+}
+
+void pgf_disconnect()
+{
+ char key;
+
+ printf("Server connection disconnected\n"
+ "Press <Enter> to close program\n");
+ while((key = getchar()) != '\n')
+ clear_input();
+}