diff options
author | Nathan Vance <nathav63@gmail.com> | 2015-02-18 19:51:17 -0500 |
---|---|---|
committer | Nathan Vance <nathav63@gmail.com> | 2015-02-18 19:51:17 -0500 |
commit | d43d5b206ae3393a19b21c36d2b8ba443ed0e121 (patch) | |
tree | a6607af121caf8a79e528ae20d6786e108136d84 | |
parent | added data to keep track of hands and what's been built (diff) | |
download | 7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.tar.gz 7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.tar.bz2 7w-d43d5b206ae3393a19b21c36d2b8ba443ed0e121.zip |
Added a view for the hand
-rw-r--r-- | data.c | 60 | ||||
-rw-r--r-- | io.c | 15 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | player_turn.c | 36 | ||||
-rw-r--r-- | util.c | 6 |
5 files changed, 113 insertions, 10 deletions
@@ -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++) { @@ -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, "############################"); +} @@ -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; + } +} @@ -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. */ |