summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cardstack.c8
-rw-r--r--src/cardstack.h2
-rw-r--r--src/display.c105
-rw-r--r--src/display.h8
-rw-r--r--src/hand.h4
-rw-r--r--src/main.c1
6 files changed, 108 insertions, 20 deletions
diff --git a/src/cardstack.c b/src/cardstack.c
index a623b1b..66cede9 100644
--- a/src/cardstack.c
+++ b/src/cardstack.c
@@ -1,13 +1,13 @@
#include "cardstack.h"
-uint32_t cardstack_get_points(const cardstack s)
+uint32_t cardstack_get_points(const cardstack cs)
{
uint32_t points = 0;
- for(int i = 0; i < MAX_CARDSTACK_SIZE; i++)
+ for(uint8_t i = 0; i < MAX_CARDSTACK_SIZE; i++)
{
- if(s[i] > 0)
- points += card_get_points(s[i]);
+ if(cs[i] > 0)
+ points += card_get_points(cs[i]);
}
return points;
diff --git a/src/cardstack.h b/src/cardstack.h
index d77996d..119bd4d 100644
--- a/src/cardstack.h
+++ b/src/cardstack.h
@@ -8,6 +8,6 @@
typedef card cardstack[MAX_CARDSTACK_SIZE];
-uint32_t cardstack_get_points(const cardstack s);
+uint32_t cardstack_get_points(const cardstack cs);
#endif // OXEN_CARDSTACK_H
diff --git a/src/display.c b/src/display.c
index 8ed3d73..f9730dc 100644
--- a/src/display.c
+++ b/src/display.c
@@ -8,8 +8,12 @@
#define CP_RED_ON_BLACK 5
static bool colors = false;
+static WINDOW *w_table_cards;
+static WINDOW *w_stack_points;
+static WINDOW *w_current_state;
+static WINDOW *w_hand_cards;
-void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const card c)
+static void draw_card(WINDOW *w, const uint8_t row, const uint8_t col, const card c)
{
unsigned color_pair = 0;
@@ -33,7 +37,7 @@ void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const
color_pair = CP_WHITE_ON_BLACK;
}
- attron(COLOR_PAIR(color_pair));
+ wattron(w, COLOR_PAIR(color_pair));
}
mvwaddch(w, row, col, ACS_ULCORNER); // Upper left corner
@@ -89,10 +93,76 @@ void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const
if (colors)
{
- attroff(COLOR_PAIR(color_pair));
+ wattroff(w, COLOR_PAIR(color_pair));
}
}
+static void draw_cardstack(WINDOW *w, const uint8_t row, const uint8_t col, const cardstack cs)
+{
+ for (uint8_t i = 0; i < MAX_CARDSTACK_SIZE; i++)
+ {
+ if (cs[i] != 0)
+ {
+ draw_card(w, row, i*2, cs[i]);
+ }
+ }
+}
+
+void display_window_table_cards(const tablestacks ts)
+{
+ mvwprintw(w_table_cards, 0, 2, "Table Cards:");
+
+ for (uint8_t i = 0; i < NUM_TABLESTACKS; i++)
+ {
+ draw_cardstack(w_table_cards, 1 + i*5, 0, ts[i]);
+ }
+
+ wrefresh(w_table_cards);
+}
+
+void display_window_stack_points(const tablestacks ts)
+{
+ mvwprintw(w_stack_points, 0, 0, "Pts:");
+
+ for (uint8_t i = 0; i < NUM_TABLESTACKS; i++)
+ {
+ mvwprintw(w_stack_points, 3 + i*5, 1, "%2d", i*5);
+ }
+
+ wrefresh(w_stack_points);
+}
+
+/**
+ * Displays the current state window.
+ * @param[in] score The players score
+*/
+void display_window_current_state(const uint32_t score)
+{
+ mvwprintw(w_current_state, 0, 0, "Current state:");
+ mvwprintw(w_current_state, 0, 23, "Your Score: %3d", score);
+
+ wrefresh(w_current_state);
+}
+
+/**
+ * Displays the hand cards window.
+ * @param[in] h The hand that will be displayed. h must not contain 0
+*/
+void display_window_hand_cards(const hand h)
+{
+ mvwprintw(w_hand_cards, 0, 0, "Hand Cards:");
+
+ for (uint8_t i = 0; i < MAX_HAND_CARDS; i++)
+ {
+ if (i < 5) // Start with the first row of cards
+ draw_card(w_hand_cards, 1, i*8, h[i]);
+ else // And then draw the second row
+ draw_card(w_hand_cards, 6, (i-5)*8, h[i]);
+ }
+
+ wrefresh(w_hand_cards);
+}
+
void display_init(void)
{
initscr(); // Start curses mode
@@ -113,19 +183,32 @@ void display_init(void)
nodelay(stdscr, true); // Non-blocking input
noecho(); // Don't echo() while we do getch
curs_set(0); // Make the cursor invisible
-
clear();
refresh();
- int j = 0;
- for (int i = 45; i < 70; i++)
- {
- display_draw_card(stdscr, 0, j++*2, i+1);
- usleep(750000);
- refresh();
- }
+
+ w_table_cards = newwin(21, 15, 0, 0);
+ w_stack_points = newwin(19, 4, 0, 17);
+ w_current_state = newwin(10, 38, 0, 24);
+ w_hand_cards = newwin(11, 39, 10, 24);
+
+ const tablestacks ts = {{1, 2, 3, 4, 101}, {6, 7, 53, 0, 0}, {11, 55, 0, 0, 0}, {17, 29, 36, 42, 0}};
+ const hand h = {12, 13, 22, 25, 27, 69, 77, 85, 100, 103};
+ const uint32_t score = 10;
+ mvvline(0, 22, ACS_VLINE, 21); // Vertical line
+ refresh();
+ display_window_table_cards(ts);
+ display_window_stack_points(ts);
+ display_window_current_state(score);
+ display_window_hand_cards(h);
+ //refresh();
+ sleep(3);
}
void display_fini(void)
{
+ delwin(w_table_cards);
+ delwin(w_stack_points);
+ delwin(w_current_state);
+ delwin(w_hand_cards);
endwin(); // End curses mode
}
diff --git a/src/display.h b/src/display.h
index 04b639f..8e9b3c4 100644
--- a/src/display.h
+++ b/src/display.h
@@ -3,8 +3,14 @@
#include <curses.h>
#include "card.h"
+#include "cardstack.h"
+#include "tablestacks.h"
+#include "hand.h"
-void display_draw_card(WINDOW *w, const uint32_t row, const uint32_t col, const card c);
+void display_window_table_cards(const tablestacks ts);
+void display_window_stack_points(const tablestacks ts);
+void display_window_current_state(const uint32_t score);
+void display_window_hand_cards(const hand h);
void display_init(void);
void display_fini(void);
diff --git a/src/hand.h b/src/hand.h
index 9268fd8..f9feb6e 100644
--- a/src/hand.h
+++ b/src/hand.h
@@ -3,8 +3,8 @@
#include "card.h"
-#define MAX_HAND_SIZE 10
+#define MAX_HAND_CARDS 10
-typedef card hand[MAX_HAND_SIZE];
+typedef card hand[MAX_HAND_CARDS];
#endif // OXEN_HAND_H
diff --git a/src/main.c b/src/main.c
index d4e7383..35673d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,6 @@
#include <unistd.h>
#include <curses.h>
#include "display.h"
-#include "card.h"
int main(int argc, char **argv)
{