back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/linux_client/printing_game_frames.c
blob: 6b2131a537e3d1d060c1806d3016bc7721068669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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();
}