aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c60
-rw-r--r--io.c15
-rw-r--r--main.c6
-rw-r--r--player_turn.c36
-rw-r--r--util.c6
5 files changed, 113 insertions, 10 deletions
diff --git a/data.c b/data.c
index fcfb5f5..fe81c90 100644
--- a/data.c
+++ b/data.c
@@ -3,6 +3,7 @@
int* getdeck(int era, int numplayers);
int* cards_getproduction(int era, int card);
int* get_intarray(int size);
+void array_cpy(int *a, int *b, int len); //copies b to a
#define MISC 3
#define DATAGOLD 0
@@ -11,6 +12,18 @@ static int decks[3][49];
static int player[7][4][7]; //3 eras and extra stuff (gold, military wins/defeats, etc.)
static int hands[7][7];
static int numplayers;
+static int era;
+
+void data_nextera()
+{
+ if(era == 2) return;
+ era++;
+ int i, j, k;
+ k = 0;
+ for(i = 0; i < numplayers; i++)
+ for(j = 0; j < 7; j++)
+ hands[i][j] = decks[era][k++];
+}
void data_init(int n)
{
@@ -18,24 +31,53 @@ void data_init(int n)
int i, j, *deck;
for(i = 0; i < 3; i++) {
deck = getdeck(i, numplayers);
- for(j = 0; j < numplayers; j++)
+ for(j = 0; j < numplayers*7; j++)
decks[i][j] = deck[j];
}
+ era = -1;
+ data_nextera();
+}
+
+void data_passturn()
+{ //remember, player numbers are arranged clockwise
+ int buffer[7], i;
+ if(era == 0 || era == 2) { //pass to the left
+ array_cpy(buffer, hands[numplayers-1], 7);
+ for(i = numplayers-1; i > 0; i--) {
+ array_cpy(hands[i], hands[i-1], 7);
+ }
+ array_cpy(hands[0], buffer, 7);
+ } else { //pass to the right
+ array_cpy(buffer, hands[0], 7);
+ for(i = 0; i < numplayers-1; i++) {
+ array_cpy(hands[i], hands[i+1], 7);
+ }
+ array_cpy(hands[numplayers-1], buffer, 7);
+ }
}
-void data_startera(int era)
+int* data_gethand(int p)
{
- int i, j, k;
- k = 0;
- for(i = 0; i < numplayers; i++)
- for(j = 0; j < 7; j++)
- hands[i][j] = decks[era][k++];
+ return hands[p];
+}
+
+int data_getera()
+{
+ return era;
+}
+
+void data_build(int p, int card)
+{
+ int i;
+ for(i = 0; hands[p][i] != card; i++);
+ for(; i < 7; i++) hands[p][i] = hands[p][i+1];
+ hands[p][7] = -1;
}
//0 is non producing, 1 produces one kind of resource, 2 produces multiple resources
-int data_productiontype(int era, int card)
+int data_productiontype(int e, int card)
{
- int *prod = cards_getproduction(era, card);
+ int *prod = cards_getproduction(e, card);
int i;
int type = 0;
for(i = 0; i < GOLD; i++) {
diff --git a/io.c b/io.c
index 738bbdf..1b384c1 100644
--- a/io.c
+++ b/io.c
@@ -11,6 +11,8 @@ int gettypecolor(int type);
int* cards_getcoupons(int era, int card);
int* cards_getcouponed(int era, int card);
char* cards_specialmessage(int era, int card);
+int data_getera();
+int* data_gethand(int p);
void io_init()
{
@@ -166,3 +168,16 @@ void io_printcard(int x, int y, int era, int card)
mvprintw(y++, x, "############################");
}
+
+void io_printhand(int x, int y, int player, int cursor)
+{
+ int *hand = data_gethand(player);
+ int i;
+ mvprintw(y++, x, "############################");
+ for(i = 0; hand[i] != -1 && i < 7; i++) {
+ io_printname(x, y++, data_getera(), hand[i]);
+ if(i == cursor) mvprintw(y-1, x+25, "*");
+ refresh();
+ }
+ mvprintw(y++, x, "############################");
+}
diff --git a/main.c b/main.c
index 303b52c..1b07017 100644
--- a/main.c
+++ b/main.c
@@ -7,6 +7,8 @@ void io_printcard(int x, int y, int era, int card);
void cardtour();
void io_clearscreen();
int* getdeck(int era, int numplayers);
+void data_init(int num_players);
+void player_turn(int player);
void halt()
{
@@ -18,7 +20,9 @@ main()
{
io_init();
cards_init();
- cardtour();
+ data_init(4);
+// cardtour();
+ player_turn(1);
halt();
}
diff --git a/player_turn.c b/player_turn.c
new file mode 100644
index 0000000..8c0f889
--- /dev/null
+++ b/player_turn.c
@@ -0,0 +1,36 @@
+#include "7w.h"
+
+int* data_gethand(int p);
+int data_getera();
+void io_printhand(int x, int y, int player, int cursor);
+void io_printcard(int x, int y, int era, int card);
+int io_getkey();
+void data_passturn();
+void io_clearscreen();
+void data_nextera();
+
+void player_turn(int player)
+{
+ int *hand = data_gethand(player);
+ int numcards;
+ for(numcards = 0; numcards < 7 && hand[numcards] > -1; numcards++);
+ int cursor = 0;
+ while(1) {
+ io_clearscreen();
+ io_printhand(0, 0, player, cursor);
+ io_printcard(0, 8, data_getera(), hand[cursor]);
+ switch(io_getkey()) {
+ case UP: cursor--;
+ break;
+ case DOWN: cursor++;
+ break;
+ case RIGHT: data_passturn();
+ break;
+ case ENTER: data_nextera();
+ break;
+ default: break;
+ }
+ if(cursor < 0) cursor = numcards-1;
+ if(cursor >= numcards) cursor = 0;
+ }
+}
diff --git a/util.c b/util.c
index 829e7d1..93c5904 100644
--- a/util.c
+++ b/util.c
@@ -26,6 +26,12 @@ char* get_chararray(int size)
return ret;
}
+void array_cpy(int *a, int *b, int len) //copies b to a
+{
+ int i;
+ for(i = 0; i < len; i++) a[i] = b[i];
+}
+
/* In string a[], replace nth occerence of x[] with y[],
or all occerences if n == 0. Note '.' is wild and
the last . replaced will be returned. */
bgstack15