#include "game.h" #include "card.h" #include "hand.h" #include #include #include #include #include #include #include #include "ui.h" #include "global.h" #include "net.h" static void init_mainstack(card *stack, const uint32_t size) { assert(stack != NULL); // assign card values to main stack for(uint32_t i=0, val=MIN_CARD; itable_stacks = { { _cs1, _cs2, _cs3, _cs4 } }; data->table_stacks.stacks[0] = _cs1; data->table_stacks.stacks[1] = _cs2; data->table_stacks.stacks[2] = _cs3; data->table_stacks.stacks[3] = _cs4; //const table_stacks_t ts = { { _cs1, _cs2, _cs3, _cs4 } }; // 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] = { {0, "$you", 10}, {1, "1234567890", 23}, {2, "baz", 38}, {3, "foo_bar", 14}, {4, "lolcat", 60}, {5, "blablub123", 15}, {6, "abcdefg", 103}, {7, "hello", 98}, {8, "hornoxe", 33}, {9, "1337nick", 74} }; pnoc_sort(pnoc, 10); const uint8_t num_players = 10; const uint32_t score = 10; // Example data set for hand cards window const hand_t h = { {22, 0, 12, 85, 27, 69, 78, 0, 77, 0} }; data->hand = h; hand_sort(&data->hand); if(servermode) { pid_t child = fork(); server_process = (child > 0); } if(server_process) // Start server and connect to localhost { int ssock; uint8_t num_opponents = 1; ssock = server_start(port); server_get_players(ssock, num_opponents); main_loop_server(); } else // Connect to server { int sock; sleep(1); // TODO make sure server process is listening sock = client_connect_server(addr, port); client_hello(sock, "nickname_client"); net_recv(sock, msg_type_start_game); net_recv(sock, msg_type_deal_cards); ui_init(); // Display all windows ui_display_wnd_table_cards(&data->table_stacks, false, 0); ui_display_wnd_stack_points(&data->table_stacks, false, 0); ui_display_wnd_current_state(pnoc, num_players, 2, score); ui_display_wnd_hand_cards(&data->hand, false, 0); main_loop_client(); ui_fini(); } }