diff options
-rw-r--r-- | cards.c | 33 | ||||
-rw-r--r-- | io.c | 55 | ||||
-rw-r--r-- | main.c | 4 |
3 files changed, 69 insertions, 23 deletions
@@ -1,5 +1,11 @@ #include "7w.h" +#define STARTCOST 1 +#define STARTPRODUCTION 1+NUMRESOURCES +#define STARTCOUPONS 1+NUMRESOURCES+NUMPRODUCTS +#define STARTCOUPONED 1+NUMRESOURCES+NUMPRODUCTS+4 + + char* get_chararray(int size); int* get_intarray(int size); @@ -9,20 +15,20 @@ static int cards[3][CARDSPERERA][60]; void cards_setcost(int era, int card, int res, int num) { - cards[era][card][res+1] = num; + cards[era][card][STARTCOST+res] = num; } int* cards_getcost(int era, int card) { int *ret = get_intarray(NUMRESOURCES); int i; - for(i = 0; i < NUMRESOURCES; i++) ret[i] = cards[era][card][i+1]; + for(i = 0; i < NUMRESOURCES; i++) ret[i] = cards[era][card][STARTCOST+i]; return ret; } void cards_setproduction(int era, int card, int res, int num) { - cards[era][card][res+1+NUMRESOURCES] = num; + cards[era][card][STARTPRODUCTION+res] = num; } int* cards_getproduction(int era, int card) @@ -30,7 +36,7 @@ int* cards_getproduction(int era, int card) int *ret = get_intarray(NUMPRODUCTS); int i; for(i = 0; i < NUMPRODUCTS; i++) - ret[i] = cards[era][card][i+1+NUMRESOURCES]; + ret[i] = cards[era][card][STARTPRODUCTION+i]; return ret; } @@ -46,7 +52,7 @@ int cards_gettype(int era, int card) void cards_setcoupons(int era, int card, int era1, int card1, int era2, int card2) { - int i = 1+NUMRESOURCES+NUMPRODUCTS; + int i = STARTCOUPONS; cards[era][card][i++] = era1; cards[era][card][i++] = card1; cards[era][card][i++] = era2; @@ -59,7 +65,7 @@ int* cards_getcoupons(int era, int card) int *ret = get_intarray(4); int i; for(i = 0; i < 4; i++) - ret[i] = cards[era][card][1+NUMRESOURCES+NUMPRODUCTS+i]; + ret[i] = cards[era][card][STARTCOUPONS+i]; return ret; } @@ -69,19 +75,26 @@ int* cards_getcouponed(int era, int card) int *ret = get_intarray(4); int i; for(i = 0; i < 4; i++) - ret[i] = cards[era][card][1+NUMRESOURCES+NUMPRODUCTS+4+i]; + ret[i] = cards[era][card][STARTCOUPONED+i]; return ret; } void cards_updatecoupons() { int i, j, k; + int* card; for(i = 0; i <= 1; i++) { for(j = 0; j < CARDSPERERA; j++) { - for(k = 1+NUMRESOURCES+NUMPRODUCTS; k <= 3+NUMRESOURCES+NUMPRODUCTS; k += 2) { + for(k = STARTCOUPONS; k <= STARTCOUPONS+2; k += 2) { if(cards[i][j][k] != 0) { - cards[cards[i][j][k]][cards[i][j][k+1]][k+4] = i; - cards[cards[i][j][k]][cards[i][j][k+1]][k+5] = j; + card = cards[cards[i][j][k]][cards[i][j][k+1]]; + if(card[STARTCOUPONED+1]) { + card[STARTCOUPONED+2] = i; + card[STARTCOUPONED+3] = j; + } else { + card[STARTCOUPONED+0] = i; + card[STARTCOUPONED+1] = j; + } } } } @@ -8,6 +8,8 @@ int cards_gettype(int era, int card); int* cards_getproduction(int era, int card); char* getname(int res); int gettypecolor(int type); +int* cards_getcoupons(int era, int card); +int* cards_getcouponed(int era, int card); void io_init() { @@ -59,28 +61,59 @@ int c; } } -void io_printcard(int x, int y, int era, int card) +void io_printname(int x, int y, int era, int card) { - mvprintw(y++, x, "################################"); - mvprintw(y++, x, "# "); + mvprintw(y, x, "# "); attron(COLOR_PAIR(gettypecolor(cards_gettype(era, card)))); - printw("%-28s", cards_getname(era, card)); + printw("%-24s", cards_getname(era, card)); attrset(A_NORMAL); printw(" #"); - mvprintw(y++, x, "# Cost (and): | Products (or): #"); +} + +void io_printcard(int x, int y, int era, int card) +{ + mvprintw(y++, x, "############################"); + io_printname(x, y++, era, card); + mvprintw(y++, x, "# Costs: | Produces: #"); int *costs = cards_getcost(era, card); int *products = cards_getproduction(era, card); - int i, j; + int i, j, k; i = j = -1; while(i < NUMRESOURCES || j < NUMPRODUCTS) { while(i < NUMRESOURCES && costs[++i] == 0); while(j < NUMPRODUCTS && products[++j] == 0); if(i == NUMRESOURCES && j == NUMPRODUCTS) break; mvprintw(y++, x, "# "); - if(i < NUMRESOURCES) printw(" %d %-9s| ", costs[i], getname(i)); - else printw(" | "); - if(j < NUMPRODUCTS) printw(" %d %-11s #", products[j], getname(j)); - else printw(" #"); + if(i < NUMRESOURCES) printw(" %d %-6s| ", costs[i], getname(i)); + else printw(" | "); + int isFinal = 1; + for(k = j+1; k < NUMPRODUCTS; k++) + if(products[k]) isFinal = 0; + if(j < NUMPRODUCTS) + if(isFinal) printw(" %d %-10s #", products[j], getname(j)); + else printw(" %d %-7s or #", products[j], getname(j)); + else printw(" #"); + } + + int* coupons = cards_getcoupons(era, card); + if(coupons[1] || coupons[3]) + { //print the coupons! + mvprintw(y++, x, "# Coupon for: #"); + if(coupons[1] != 0) + io_printname(x, y++, coupons[0], coupons[1]); + if(coupons[3] != 0) + io_printname(x, y++, coupons[2], coupons[3]); } - mvprintw(y++, x, "################################"); + + coupons = cards_getcouponed(era, card); + if(coupons[0] || coupons[2]) + { //print the coupons! + mvprintw(y++, x, "# Free if owned: #"); + if(coupons[0] != 0) + io_printname(x, y++, coupons[0], coupons[1]); + if(coupons[2] != 0) + io_printname(x, y++, coupons[2], coupons[3]); + } + + mvprintw(y++, x, "############################"); } @@ -16,8 +16,8 @@ main() io_init(); cards_init(); io_printcard(0, 0, 0, 0); - io_printcard(0, 4, 2, 14); - io_printcard(0, 10, 2, 3); + io_printcard(0, 6, 2, 14); + io_printcard(0, 20, 2, 3); io_printcard(31, 0, 1, 12); io_getkey(); halt(); |