From 73f8ff5e1cf46ddb9ebf25f92e8ad51aae09f029 Mon Sep 17 00:00:00 2001 From: Nathan Vance Date: Thu, 19 Feb 2015 11:16:00 -0500 Subject: added a basic view for wonders --- cards.c | 2 +- data.c | 41 ++++++++++++++++++++++++++++++++++++-- io.c | 24 ++++++++++++++--------- main.c | 2 ++ wonder.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 wonder.c diff --git a/cards.c b/cards.c index a38f67c..6b9cb3e 100644 --- a/cards.c +++ b/cards.c @@ -140,7 +140,7 @@ char* getname(int res) case ORE: return "ore"; case CLOTH: return "cloth"; case GLASS: return "glass"; - case PAPER: return "papyrus"; + case PAPER: return "paper"; case GOLD: return "gold"; case COMPASS: return "compass"; case GEAR: return "gear"; diff --git a/data.c b/data.c index fe81c90..41317b4 100644 --- a/data.c +++ b/data.c @@ -1,15 +1,17 @@ #include "7w.h" +#include 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 +void shuffle(int *deck, int n); #define MISC 3 #define DATAGOLD 0 static int decks[3][49]; -static int player[7][4][7]; //3 eras and extra stuff (gold, military wins/defeats, etc.) +static int player[7][4][7]; //3 eras and extra stuff (wonder, wonder side, wonder stages completed, gold, military wins, defeats) static int hands[7][7]; static int numplayers; static int era; @@ -25,10 +27,23 @@ void data_nextera() hands[i][j] = decks[era][k++]; } +void data_distributewonders(int n) +{ + int i; + int wonders[7]; + for(i = 0; i < 7; i++) + wonders[i] = i+3; //wonders are numbered 3-9 + shuffle(wonders, 7); + for(i = 0; i < n; i++) { + player[i][3][0] = wonders[i]; + player[i][3][1] = rand()%2; + } +} + void data_init(int n) { numplayers = n; - int i, j, *deck; + int i, j, k, *deck; for(i = 0; i < 3; i++) { deck = getdeck(i, numplayers); for(j = 0; j < numplayers*7; j++) @@ -36,6 +51,11 @@ void data_init(int n) } era = -1; data_nextera(); + data_distributewonders(n); + for(i = 0; i < n; i++) + for(j = 0; j < 3; j++) + for(k = 0; k < 7; k++) + player[i][j][k] = -1; } void data_passturn() @@ -66,12 +86,29 @@ int data_getera() return era; } +int data_getwonder(int p) +{ + return player[p][3][0]; +} + +int data_getwonderside(int p) +{ + return player[p][3][1]; +} + +int data_getwonderstages(int p) +{ + return player[p][3][2]; +} + 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; + for(i = 0; player[p][era][i] != -1; i++); + player[p][era][i] = card; } //0 is non producing, 1 produces one kind of resource, 2 produces multiple resources diff --git a/io.c b/io.c index 1b384c1..60d8536 100644 --- a/io.c +++ b/io.c @@ -78,7 +78,7 @@ void io_printname(int x, int y, int era, int card) printw(" #"); } -io_printblankline(int x, int y, int width) +void io_printblankline(int x, int y, int width) { int i; mvprintw(y, x, "#"); @@ -86,7 +86,7 @@ io_printblankline(int x, int y, int width) printw("#"); } -io_printtext(int xorigin, int y, int width, char* text) +int io_printtext(int xorigin, int y, int width, char* text) { width -= 2; //padding int x = xorigin+2; @@ -110,10 +110,16 @@ io_printtext(int xorigin, int y, int width, char* text) return y+1; } +void io_printborder(int x, int y) +{ + mvprintw(y, x, "############################"); +} + void io_printcard(int x, int y, int era, int card) { - mvprintw(y++, x, "############################"); - io_printname(x, y++, era, card); + io_printborder(x, y++); + if(cards_getname(era, card)[0] != '\0') + io_printname(x, y++, era, card); int *costs = cards_getcost(era, card); int *products = cards_getproduction(era, card); int hasCP = 0; @@ -136,7 +142,7 @@ void io_printcard(int x, int y, int era, int card) for(k = j+1; k < NUMPRODUCTS; k++) if(products[k]) isFinal = 0; if(j < NUMPRODUCTS) - if(isFinal) printw(" %d %-10s #", products[j], getname(j)); + if(isFinal || j == GOLD || j == SHIELD || j == VP) printw(" %d %-10s #", products[j], getname(j)); else printw(" %d %-7s or #", products[j], getname(j)); else printw(" #"); } @@ -165,19 +171,19 @@ void io_printcard(int x, int y, int era, int card) if(coupons[3]) io_printname(x, y++, coupons[2], coupons[3]); } - - mvprintw(y++, x, "############################"); + + io_printborder(x, y++); } void io_printhand(int x, int y, int player, int cursor) { int *hand = data_gethand(player); int i; - mvprintw(y++, x, "############################"); + io_printborder(x, y++); 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, "############################"); + io_printborder(x, y++); } diff --git a/main.c b/main.c index 1b07017..5ab0da7 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,7 @@ void io_clearscreen(); int* getdeck(int era, int numplayers); void data_init(int num_players); void player_turn(int player); +void wonder_selected(int player); void halt() { @@ -22,6 +23,7 @@ main() cards_init(); data_init(4); // cardtour(); + wonder_selected(0); player_turn(1); halt(); } diff --git a/wonder.c b/wonder.c new file mode 100644 index 0000000..282fe3f --- /dev/null +++ b/wonder.c @@ -0,0 +1,68 @@ +#include "7w.h" + +int* cards_getcost(int wonder, int stage); //remember the stage offset! +int* cards_getproduction(int wonder, int stage); +char* cards_getname(int wonder, int stage); //stage should always be 0 +char* cards_specialmessage(int wonder, int stage); +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 data_getwonderstages(int p); +char* cat(char a[], char b[]); +char* itoa(int i); +int io_getkey(); +void io_clearscreen(); + +int wonder_hasstage(int wonder, int side, int stage) +{ + 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; +} + +void print_wonder(int x, int y, int player, int cursor) +{ + io_printborder(x, y++); + y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0)); + int i; + for(i = 0; wonder_hasstage(data_getwonder(player), data_getwonderside(player), i); i++) { + char *text = cat("Stage ", itoa(i+1)); + if(data_getwonderstages(player) > i) + text = cat(text, " (complete)"); + else + text = cat(text, " "); + if(cursor == i) + text = cat(text, " *"); + else + text = cat(text, " "); + y = io_printtext(x, y, 29, text); + } + if(wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor)) + io_printcard(x, y, data_getwonder(player), cursor+1+3*data_getwonderside(player)); +} + +void wonder_selected(int player) +{ + int cursor = 0; + while(1) { + io_clearscreen(); + print_wonder(0, 0, player, cursor); + switch(io_getkey()) { + case UP: cursor--; + break; + case DOWN: cursor++; + break; + case ENTER: data_distributewonders(4); + default: break; + } + if(cursor < 0) cursor = 0; + if(! wonder_hasstage(data_getwonder(player), data_getwonderside(player), cursor)) + cursor--; + } +} -- cgit