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
|
#include "game.h"
#include "card.h"
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <curses.h>
#include "ui.h"
void init_mainstack(card* stack, const uint32_t size)
{
// assign card values to main stack
for(uint32_t i=0, val=MIN_CARD; i<size; i++, val++)
stack[i] = val;
// shuffle stack
for(uint32_t i=0; i<3*size; i++)
{
uint32_t x = rand() % size;
uint32_t y = rand() % size;
card tmp = stack[x];
stack[x] = stack[y];
stack[y] = tmp;
}
}
void start_game(const bool servermode, const char *addr, const uint16_t port)
{
bool running = true;
int cards = MAX_CARD - MIN_CARD + 1;
card mainstack[cards];
enum gamestate state = STATE_DEALCARDS;
srand(time(0));
init_mainstack(mainstack, cards);
// Example data set for table cards window
const tablestacks ts = {{1, 2, 3, 4, 101}, {6, 7, 53, 0, 0}, {11, 55, 0, 0, 0}, {17, 29, 36, 42, 0}};
// The stack points window uses ts, too, so there is no separate data set
// Example data set for current state window
pnoc_t pnoc[10] = {
{"$you", 10},
{"1234567890", 23},
{"baz", 38},
{"foo_bar", 14},
{"lolcat", 60},
{"blablub123", 15},
{"abcdefg", 103},
{"hello", 98},
{"hornoxe", 33},
{"1337nick", 74}
};
pnoc_sort(pnoc, 10);
const uint8_t num_players = 10;
const uint32_t score = 10;
// Example data set for hand cards window
hand h = {22, 0, 12, 85, 27, 69, 78, 0, 77, 0};
hand_sort(h);
// Display all windows
ui_display_wnd_table_cards(ts, false, 0);
ui_display_wnd_stack_points(ts, false, 0);
ui_display_wnd_current_state(pnoc, num_players, 2, score);
ui_display_wnd_hand_cards(h, false, 0);
// main game loop
while(running)
{
switch(state)
{
case STATE_DEALCARDS: // deal cards to players (on host)
// dealcards(mainstack);
state = STATE_SELECTCARD;
break;
case STATE_WAIT_CARDS: // wait on client until host has dealt cards
break;
case STATE_SELECTCARD: // player has to select own card, if done, set state to STATE_WAIT_OPPONENTCARDS
ui_choose_card(h);
running = false;
break;
case STATE_WAIT_OPPONENTCARDS: // wait until all opponents have selected their open card. Then check if we have the lowest open card. If so, set state to STATE_SELECTSTACK, otherwise to STATE_WAIT_OPPONENTSTACK
break;
case STATE_WAIT_OPPONENTSTACK: // wait until opponent has selected a stack
break;
case STATE_SELECTSTACK: // player has to select a stack and update it (add card/take whole stack). If it was the last player's turn, set state to STATE_SELECTCARD, otherwise to STATE_WAIT_OPPONENTSTACK
break;
default:
assert(false); // should never happen
}
}
}
|