summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.c37
-rw-r--r--src/game.h5
-rw-r--r--src/main.c51
3 files changed, 60 insertions, 33 deletions
diff --git a/src/game.c b/src/game.c
index 39dcec7..2583fb1 100644
--- a/src/game.c
+++ b/src/game.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <assert.h>
#include <curses.h>
+#include "ui.h"
void init_mainstack(card* stack, const uint32_t size)
{
@@ -24,7 +25,7 @@ void init_mainstack(card* stack, const uint32_t size)
}
}
-void start_game(void)
+void start_game(const bool servermode, const char *addr, const uint16_t port)
{
bool running = true;
int cards = MAX_CARD - MIN_CARD + 1;
@@ -35,6 +36,38 @@ void start_game(void)
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)
{
@@ -47,6 +80,8 @@ void start_game(void)
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;
diff --git a/src/game.h b/src/game.h
index a05ebbf..4675e68 100644
--- a/src/game.h
+++ b/src/game.h
@@ -1,11 +1,14 @@
#ifndef OXEN_GAME_H
#define OXEN_GAME_H
+#include <stdbool.h>
+#include <stdint.h>
+
#define MIN_CARD 1
#define MAX_CARD 104
enum gamestate { STATE_DEALCARDS, STATE_WAIT_CARDS, STATE_SELECTCARD, STATE_WAIT_OPPONENTCARDS, STATE_WAIT_OPPONENTSTACK, STATE_SELECTSTACK };
-void start_game(void);
+void start_game(const bool servermode, const char *addr, const uint16_t port);
#endif // OXEN_GAME_H
diff --git a/src/main.c b/src/main.c
index 87c7209..c6d398b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,43 +1,32 @@
#include <stdlib.h>
#include <curses.h>
#include "ui.h"
+#include "game.h"
int main(int argc, char **argv)
{
- // 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}};
+ uint16_t port = 0;
+ char *addr;
+ bool servermode = false;
- // 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);
+ if (argc < 2)
+ {
+ printf("usage: '%s address port' for client mode, or '%s port' for server mode\n", argv[0], argv[0]);
+ return EXIT_SUCCESS;
+ }
+ else if (argc == 2) // Server mode
+ {
+ servermode = true;
+ port = atoi(argv[1]);
+ }
+ else if (argc == 3) // Client mode
+ {
+ addr = argv[1];
+ port = atoi(argv[2]);
+ }
ui_init();
- 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);
-
- ui_choose_card(h);
+ start_game(servermode, addr, port);
ui_fini();
-
return EXIT_SUCCESS;
}