From e723087996663d5a1461297533e57bd2d8174585 Mon Sep 17 00:00:00 2001 From: Nathan Vance Date: Sat, 21 Feb 2015 18:06:11 -0500 Subject: Major view improvements --- cards.c | 4 ++-- data.c | 39 +++++++++++++++++++++++---------------- io.c | 21 ++++++++++++++++----- main.c | 4 ++-- player_turn.c | 23 +++++++++++++++++------ util.c | 6 ------ view.c | 47 +++++++++++++++++++++++++---------------------- wonder.c | 36 +++++++++++++++++++++--------------- 8 files changed, 106 insertions(+), 74 deletions(-) diff --git a/cards.c b/cards.c index 6b9cb3e..573bb5e 100644 --- a/cards.c +++ b/cards.c @@ -225,11 +225,11 @@ void cards_init() cards_setname(0, 17, "Tavern", COMMERCIAL); cards_setcoupons(0, 18, 1, 11, 0, 0); - cards_setmessage(0, 18, "Can trade 1 coin for resources with player to the LEFT."); + cards_setmessage(0, 18, "Can trade 1 coin for resources with player to the east."); cards_setname(0, 18, "East Trading Post", COMMERCIAL); cards_setcoupons(0, 19, 1, 11, 0, 0); - cards_setmessage(0, 19, "Can trade 1 coin for resources with player to the RIGHT."); + cards_setmessage(0, 19, "Can trade 1 coin for resources with player to the west."); cards_setname(0, 19, "West Trading Post", COMMERCIAL); cards_setcoupons(0, 20, 1, 12, 0, 0); diff --git a/data.c b/data.c index eb499cc..e07f7af 100644 --- a/data.c +++ b/data.c @@ -5,7 +5,6 @@ int* getdeck(int era, int numplayers); int* cards_getproduction(int era, int card); int cards_gettype(int era, int card); int* get_intarray(int size); -void array_cpy(int *a, int *b, int len); //copies b to a void shuffle(int *deck, int n); #define MISC 3 @@ -16,16 +15,33 @@ static int player[7][4][7]; //3 eras and extra stuff (wonder, wonder side, wonde static int hands[7][7]; static int numplayers; static int era; +static int turn; + +void data_sorthands() +{ + int i, j, k, type, buffer[7]; + for(i = 0; i < numplayers; i++) { + k = 0; + for(type = 0; type <= 7; type++) { + for(j = 0; j < 7; j++) { + if(cards_gettype(era, hands[i][j]) == type) buffer[k++] = hands[i][j]; + } + } + for(k = 0; k < 7; k++) hands[i][k] = buffer[k]; + } +} void data_nextera() { if(era == 2) return; era++; + turn = 0; int i, j, k; k = 0; for(i = 0; i < numplayers; i++) for(j = 0; j < 7; j++) hands[i][j] = decks[era][k++]; + data_sorthands(); } void data_distributewonders() @@ -61,25 +77,16 @@ void data_init(int n) 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); - } + if(era == 0 || era == 2) //pass to the left + turn++; + else //pass to the right + turn--; + if(turn < 0) turn = numplayers-1; } int* data_gethand(int p) { - return hands[p]; + return hands[(p+turn)%numplayers]; } int data_getera() diff --git a/io.c b/io.c index 60d8536..705007d 100644 --- a/io.c +++ b/io.c @@ -115,7 +115,7 @@ void io_printborder(int x, int y) mvprintw(y, x, "############################"); } -void io_printcard(int x, int y, int era, int card) +int io_printcard(int x, int y, int era, int card) { io_printborder(x, y++); if(cards_getname(era, card)[0] != '\0') @@ -172,18 +172,29 @@ void io_printcard(int x, int y, int era, int card) io_printname(x, y++, coupons[2], coupons[3]); } - io_printborder(x, y++); + io_printborder(x, y); + return y; } void io_printhand(int x, int y, int player, int cursor) { int *hand = data_gethand(player); int i; + int cursed = 0; io_printborder(x, y++); + y = io_printtext(x, y, 29, " Hand"); 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(); + if(i == cursor) { + mvprintw(y-1, x+25, "*"); + cursed = 1; + } } - io_printborder(x, y++); + if(cursed) io_printcard(x, y, data_getera(), hand[cursor]); + else io_printborder(x, y); +} + +void io_printplain(int x, int y, char *s) +{ + mvprintw(y, x, "%s", s); } diff --git a/main.c b/main.c index 0e38776..7100656 100644 --- a/main.c +++ b/main.c @@ -24,9 +24,9 @@ main() io_init(); cards_init(); data_init(7); - tester(); +// tester(); // wonder_selected(0); -// player_turn(1); + player_turn(0); halt(); } diff --git a/player_turn.c b/player_turn.c index 8c0f889..203f430 100644 --- a/player_turn.c +++ b/player_turn.c @@ -6,8 +6,10 @@ 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(); +int data_numplayers(); +void view_refresh(int focus, int cursor, int player); +int wonder_numstages(int player); void player_turn(int player) { @@ -15,10 +17,9 @@ void player_turn(int player) int numcards; for(numcards = 0; numcards < 7 && hand[numcards] > -1; numcards++); int cursor = 0; + int focus = data_numplayers(); while(1) { - io_clearscreen(); - io_printhand(0, 0, player, cursor); - io_printcard(0, 8, data_getera(), hand[cursor]); + view_refresh(focus, cursor, player); switch(io_getkey()) { case UP: cursor--; break; @@ -26,11 +27,21 @@ void player_turn(int player) break; case RIGHT: data_passturn(); break; + case LEFT: player = (player+1)%data_numplayers(); + break; case ENTER: data_nextera(); break; + case '\t': focus = (focus+1)%(data_numplayers()+1); + break; default: break; } - if(cursor < 0) cursor = numcards-1; - if(cursor >= numcards) cursor = 0; + if(focus == data_numplayers()) { + if(cursor < 0) cursor = numcards-1; + if(cursor >= numcards) cursor = 0; + } + else { + if(cursor < 0) cursor = wonder_numstages((player+focus)%data_numplayers())-1; + cursor = cursor % wonder_numstages((player+focus)%data_numplayers()); + } } } diff --git a/util.c b/util.c index 93c5904..829e7d1 100644 --- a/util.c +++ b/util.c @@ -26,12 +26,6 @@ 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. */ diff --git a/view.c b/view.c index 7d1c99a..874d43f 100644 --- a/view.c +++ b/view.c @@ -1,34 +1,37 @@ #include "7w.h" -void print_wonder(int x, int y, int player, int cursor); -void print_wondersmall(int x, int y, int player); +int print_wonder(int x, int y, int player, int cursor); +int print_wondersmall(int x, int y, int player, int selected, int dir); void io_printcard(int x, int y, int era, int card); void io_printhand(int x, int y, int player, int cursor); void io_clearscreen(); int data_numplayers(); +void io_printhand(int x, int y, int player, int cursor); -void view_refresh(int focus, int cursor, int player) +void view_printwonders(int focus, int cursor, int player) { - io_clearscreen(); - int num = data_numplayers(); - int x, y, i; - int offset = 0; - if(num == 3) x = 0; - if(num == 4 || num == 5) x = 1; - if(num == 6 || num == 7) x = 2, offset = -1; - y = 4; - int change = -1; +int num = data_numplayers(); + int x, y, i, dir; + x = y = 0; for(i = 0; i < num; i++) { - int p = (player+i+offset)%num; - if(p < 0) p += num; + int p = (player+i)%num; + dir = 0; + if(i == 1) dir = 1; + if(i == num-1) dir = 2; if(focus == p) - print_wonder(x*27, y, p, cursor); - else print_wondersmall(x*27, y, p); - if(x == 0) { - if(change == -1) change = 0; - else change = 1; - y = 0; - } - x += change; + print_wonder(34, 0, p, cursor); + y = print_wondersmall(x, y, p, focus == p, dir); + } +} + +void view_refresh(int focus, int cursor, int player) +{ + io_clearscreen(); + if(focus == data_numplayers()) { + view_printwonders(player, -1, player); + io_printhand(61, 0, player, cursor); + } else { + view_printwonders(focus, cursor, player); + io_printhand(61, 0, player, -1); } } diff --git a/wonder.c b/wonder.c index 54ecba6..36923ce 100644 --- a/wonder.c +++ b/wonder.c @@ -10,7 +10,7 @@ int data_getwonder(int p); int data_getwonderside(int p); void io_printborder(int x, int y); int io_printtext(int xorigin, int y, int width, char* text); -void io_printcard(int x, int y, int wonder, int stage); +int io_printcard(int x, int y, int wonder, int stage); void io_printname(int x, int y, int era, int card); int data_getwonderstages(int p); char* cat(char a[], char b[]); @@ -18,25 +18,26 @@ char* itoa(int i); int io_getkey(); void io_clearscreen(); int* data_getbuilt(int p); +void io_printplain(int x, int y, char *s); -int wonder_hasstage(int wonder, int side, int stage) +int wonder_numstages(int player) { - if(side == 0 && stage > 2 || stage > 3) return 0; - int *cost = cards_getcost(wonder, stage+1+side*3); - int i; - int has = 0; - for(i = 0; i < NUMPRODUCTS; i++) - if(cost[i]) has = 1; - return has; + int side = data_getwonderside(player); + int wonder = data_getwonder(player); + if(side == 0) return 3; + if(wonder == 9) return 4; + if(wonder == 3) return 2; + return 3; } -void print_wonder(int x, int y, int player, int cursor) +int print_wonder(int x, int y, int player, int cursor) { +// if(cursor != -1) cursor = cursor % wonder_numstages(player); io_printborder(x, y++); y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0)); y = io_printtext(x, y, 29, cat("Produces 1 ", getname(cards_gettype(data_getwonder(player), 0)))); int i; - for(i = 0; wonder_hasstage(data_getwonder(player), data_getwonderside(player), i); i++) { + for(i = 0; i < wonder_numstages(player); i++) { char *text = cat("Stage ", itoa(i+1)); if(data_getwonderstages(player) > i) text = cat(text, " (complete)"); @@ -58,15 +59,20 @@ void print_wonder(int x, int y, int player, int cursor) if(i == 0) y--; //Info about component - if(wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor)) - io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player)); + if(cursor >= 0 && cursor < wonder_numstages(player)) + return io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player)); } -void print_wondersmall(int x, int y, int player) +//dir is 0 for none, 1 for east, 2 for west +int print_wondersmall(int x, int y, int player, int selected, int dir) { io_printborder(x, y++); + if(selected) io_printplain(28, y, "*"); + if(dir == 1) io_printplain(29, y, "East"); + if(dir == 2) io_printplain(29, y, "West"); y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0)); io_printborder(x, y); + return y; } void wonder_selected(int player) @@ -84,7 +90,7 @@ void wonder_selected(int player) default: break; } if(cursor < 0) cursor = 0; - if(! wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor)) + if(cursor >= wonder_numstages(player)) cursor--; } } -- cgit